Relating datagrid rows to datatable rows
-
Hello, I am having a little trouble with using the windows forms datagrid control. In my program, I need to give the user the ability to select and unselect multiple rows in the datagrid and then perform some action on those selected rows. Initially, I was hoping to use checkboxes. I made a bool column in my database and added a checkbox column in my datagrid. This appeared to work okay. When I wanted to determine the selected rows, I just iterated through my data table and looked at the value of the column that was bound to the checkbox column. However, I soon found a problem with this approach. I have a "Select" menu, with different options that select thousands of rows in the datagrid (such as select all, select none, etc.) In order to do this, I needed to change the value of many checkboxes at once, and this is very very slow because I am having to edit each row in the corresponding datatable. I've been trying to figure out other ways to get the same functionality, and I thought that maybe I could just use the built-in select in the datagrid (highlighting the entire row). I was able to select large numbers of rows much more quickly this way because I wasn't modifying any data in the datatable. However, now I have another problem. I don't know how to relate a row in the datagrid to the correct row in the datatable. I've found some code examples such as this: BindingManagerBase bm = dataGrid1.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember]; DataRow dr = ((DataRowView)bm.Current).Row; But, this only works for the current row. What if I have a list of the row indexes in the datagrid, and I want to iterate through that list and perform actions on the correct row in the datatable? Also, I really prefer the checkboxes over the highlighted rows. Is there a way that I can implement checkboxes without having to make a column in my datatable? Any ideas would be great! Thanks, Blake
-
Hello, I am having a little trouble with using the windows forms datagrid control. In my program, I need to give the user the ability to select and unselect multiple rows in the datagrid and then perform some action on those selected rows. Initially, I was hoping to use checkboxes. I made a bool column in my database and added a checkbox column in my datagrid. This appeared to work okay. When I wanted to determine the selected rows, I just iterated through my data table and looked at the value of the column that was bound to the checkbox column. However, I soon found a problem with this approach. I have a "Select" menu, with different options that select thousands of rows in the datagrid (such as select all, select none, etc.) In order to do this, I needed to change the value of many checkboxes at once, and this is very very slow because I am having to edit each row in the corresponding datatable. I've been trying to figure out other ways to get the same functionality, and I thought that maybe I could just use the built-in select in the datagrid (highlighting the entire row). I was able to select large numbers of rows much more quickly this way because I wasn't modifying any data in the datatable. However, now I have another problem. I don't know how to relate a row in the datagrid to the correct row in the datatable. I've found some code examples such as this: BindingManagerBase bm = dataGrid1.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember]; DataRow dr = ((DataRowView)bm.Current).Row; But, this only works for the current row. What if I have a list of the row indexes in the datagrid, and I want to iterate through that list and perform actions on the correct row in the datatable? Also, I really prefer the checkboxes over the highlighted rows. Is there a way that I can implement checkboxes without having to make a column in my datatable? Any ideas would be great! Thanks, Blake