DataGridView problem
-
Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)
i want to record the change of value of "Primary" and "Secondary" columns.
That is I want to know if user checked or unchecked the value in any row in the last two columns
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
-
Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)
i want to record the change of value of "Primary" and "Secondary" columns.
That is I want to know if user checked or unchecked the value in any row in the last two columns
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
hi, Don't think datagrid, think datasource. So ure solution is in the the datatable. use the ColumnChanged or ColumnChanging event of ure datatabl. Here an example : mydataTable.ColumnChanged += new DataColumnChangeEventHandler(mydataTable_ColumnChanged); void mydataTable_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (e.Column.ColumnName == "Primary" ||e.Column.ColumnName == "Secondary") { if (e.PropsedValue == true ) { //............. do something } } } HTH. Hayder Marzouk
-
Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)
i want to record the change of value of "Primary" and "Secondary" columns.
That is I want to know if user checked or unchecked the value in any row in the last two columns
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
Are you just trying to retrieve the data from the datagridview columns? or are you trying to capture them into events. if it's the former, then you can simply do this:
dataGridView1.Columns.Add("foo", "foo"); DataGridViewCheckBoxColumn cbc = new DataGridViewCheckBoxColumn(); cbc.Name = "bar"; dataGridView1.Columns.Add(cbc); dataGridView1.Rows.Add("xyzzy", true); dataGridView1.Rows.Add("yzzyx", false); Console.WriteLine((bool)((dataGridView1.Rows[0].Cells[1]).Value)); Console.WriteLine((bool)((dataGridView1.Rows[1].Cells[1]).Value));
Cast the value of the cell you need into a bool, and you have the Checked value. ps: please don't randomly place layout tags over text in your post, makes it hard to read.
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
-
hi, Don't think datagrid, think datasource. So ure solution is in the the datatable. use the ColumnChanged or ColumnChanging event of ure datatabl. Here an example : mydataTable.ColumnChanged += new DataColumnChangeEventHandler(mydataTable_ColumnChanged); void mydataTable_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (e.Column.ColumnName == "Primary" ||e.Column.ColumnName == "Secondary") { if (e.PropsedValue == true ) { //............. do something } } } HTH. Hayder Marzouk
That would only work if the datagridview was databound I think. If there is no underlying datasource/table you have to access the DGV directly. You can also use the datagridview.Click event to capture whether a checkbox was clicked, and get it's new value in the way I described below.
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }