How to get DataGridView Checkbox Checked or not ! [modified]
-
I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks
modified on Tuesday, April 6, 2010 7:50 AM
-
I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks
modified on Tuesday, April 6, 2010 7:50 AM
-
Hi, I'm using something like this;
bool IsChecked = (bool)row.Cells[0].Value;
I are Troll :suss:
-
Sr...Frank wrote:
Not Working! Error: Object reference not set to an instance of an object.
I'm guessing that "row" is
NULL
. Try this;for(int i; i < datagridview1.rows.count; i++)
{
bool IsChecked = (bool)datagridview1.rows[i].Cells[0].Value;
}You can try the code below to compare against, should display the basic idea;
public partial class MainForm : Form
{
DataGridView grid = new DataGridView();
Button testButton = new Button();public MainForm() { InitializeComponent(); testButton.Dock = DockStyle.Bottom; testButton.Click += delegate { bool result = (bool)grid.Rows\[0\].Cells\[0\].Value; MessageBox.Show("Checked: " + result); }; grid.Dock = DockStyle.Fill; grid.Columns.Add(new DataGridViewCheckBoxColumn()); grid.Rows.Add(true); grid.Rows.Add(false); Controls.Add(grid); Controls.Add(testButton); }
}
Enjoy :)
I are Troll :suss:
-
I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks
modified on Tuesday, April 6, 2010 7:50 AM
-
Please change "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked;" to "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].FindControl["CheckBox1"]).Checked;" and have another try.
Not Working: Error:Object reference not set to an instance of an object. I am not able to use FindControl[] in windows applications using c# .net. So please does any one will provide my the suitable code.