How to Delete View on the DataGridView Checkbox?

How to Delete View on the DataGridView Checkbox?

Anonymous
Not applicable
745 Views
7 Replies
Message 1 of 8

How to Delete View on the DataGridView Checkbox?

Anonymous
Not applicable

Hi everybody
I have a Datagridview table of Windown Form that lists all the views in Revit. Now I want to delete the views when I check the selected box. Can you help me?

Datgrid.PNG

0 Likes
746 Views
7 Replies
Replies (7)
Message 2 of 8

1240904365
Enthusiast
Enthusiast
Accepted solution

doc.Delete(view.Id)

0 Likes
Message 3 of 8

Anonymous
Not applicable
Accepted solution

hi.

doc.Delete(View.id) is delete all view. I want to delete view when I check on the DataGridView.

0 Likes
Message 4 of 8

1240904365
Enthusiast
Enthusiast
Accepted solution

You can create a new class that has the properties view id and bool IsChecked, bind this class to your datagrid, and get the view id you want by checking the checkbox. if you don't understand, you can go to the msdn WPF forum for help.

0 Likes
Message 5 of 8

Anonymous
Not applicable
Accepted solution

sorry, I am writing on windows form

0 Likes
Message 6 of 8

RPTHOMAS108
Mentor
Mentor
Accepted solution

How you go about this would depend on what the DataGridView contains i.e. did you use DataGridView.DataSource or did you manually populate? What does each row represent in terms of the data object?

 

If you have some backing data source then that is what you should be querying for the checked items, if you don't you'll have to iterate the view and collect up the rows with a checked item.

0 Likes
Message 7 of 8

Anonymous
Not applicable
Accepted solution

hi..

this is my code..but it only deletes the row on datagridview and the data "View" in Revit, it deletes all. Can I delete data in revit based on datagridview's checkbox table? Can you help me?

 

private void btnPurge_Click(object sender, EventArgs e)
{

int num = 0;

#region(test 2)
List<DataGridViewRow> selectedRows = (from row in datagridView1.Rows.Cast<DataGridViewRow>()
where Convert.ToBoolean(row.Cells["chk"].Value) == true
select row).ToList();


if (MessageBox.Show(string.Format("Do you want to delete {0} rows?", selectedRows.Count),
"Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
foreach (DataGridViewRow row in selectedRows)
{
datagridView1.Rows.Remove(row);
foreach (View view in allView)
{
Transaction tx2 = new Transaction(doc);
tx2.Start("Delete View");

doc.Delete(view.Id);
num += 1;


tx2.Commit();

}
}

}

0 Likes
Message 8 of 8

RPTHOMAS108
Mentor
Mentor

You have collections

selectedRows

allView

 

There is no apparent relationship between the two and you are deleting everything in allViews from Revit. You need to filter allView based on selectedRows perhaps.

 

Note also that some dependant views will also be deleted when their parent is deleted. So overall this is not a good way to complete your task. You need to work out such relationships and TreeView form of display is more appropriate for showing that.

 

Would also strongly suggest data binding rather than manual population of content controls since it'll make life easier i.e. manage one collection not two.

 

 

0 Likes