DataGrid Checkbox Event capture
-
Hi All, I have a C# Windows Form, which contains a DataGrid, and one of the column in the DaatrGrid is Checkbox. What I need to do is - when checkbox is checked, all other checkboxes should be unchecked. For ex: if there are 10 rows in DataGrid, and Row - 2 has checkbox checked. Now when "Checkbox column of Row - 5" is clicked, it should un-check "Checkbox column of Row - 2" . Please let me know how can I capture check_event and loop through all rows. Any help or pointers :confused: Thanks in Advance :rolleyes: Ruchi
-
Hi All, I have a C# Windows Form, which contains a DataGrid, and one of the column in the DaatrGrid is Checkbox. What I need to do is - when checkbox is checked, all other checkboxes should be unchecked. For ex: if there are 10 rows in DataGrid, and Row - 2 has checkbox checked. Now when "Checkbox column of Row - 5" is clicked, it should un-check "Checkbox column of Row - 2" . Please let me know how can I capture check_event and loop through all rows. Any help or pointers :confused: Thanks in Advance :rolleyes: Ruchi
Actually, it's not a
CheckBox
. A check box is merely drawn by theDataGridBoolColumn
using eitherControlPaint.DrawMixedCheckBox
orControlPaint.DrawCheckBox
, depending on whether or not the column allows nulls (DBNull
). If you want to use an actualCheckBox
and expose the event (better to encapsulate theCheckBox
and expose only what's needed), you'll have to derive your ownDataGridColumnStyle
. See the documentation for that class in the .NET Framework SDK, which also includes a sample using aDateTimePicker
control.Microsoft MVP, Visual C# My Articles
-
Hi All, I have a C# Windows Form, which contains a DataGrid, and one of the column in the DaatrGrid is Checkbox. What I need to do is - when checkbox is checked, all other checkboxes should be unchecked. For ex: if there are 10 rows in DataGrid, and Row - 2 has checkbox checked. Now when "Checkbox column of Row - 5" is clicked, it should un-check "Checkbox column of Row - 2" . Please let me know how can I capture check_event and loop through all rows. Any help or pointers :confused: Thanks in Advance :rolleyes: Ruchi
Oh, I almost forgot: if you're using a
DataSet
orDataTable
for binding, you can handle theDataTable.ColumnChanging
orDataTable.ColumnChangeed
event and then enumerate theDataRows in the `DataTable` and change what you need accordingly. Microsoft MVP, Visual C# [My Articles](http://www.codeproject.com/script/articles/list_articles.asp?userid=46969)
-
Oh, I almost forgot: if you're using a
DataSet
orDataTable
for binding, you can handle theDataTable.ColumnChanging
orDataTable.ColumnChangeed
event and then enumerate theDataRows in the `DataTable` and change what you need accordingly. Microsoft MVP, Visual C# [My Articles](http://www.codeproject.com/script/articles/list_articles.asp?userid=46969)
Thanks so much for your response. I will work towards this pointer Ruchi:|