Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to type cast DataGridViewCheckboxColumn field value in check box.
C#
CheckBox asa = (CheckBox)dataGridview1.Rows[1].Cells[3];


this field is allready datagridviewchechkboxcolumn
i m facing problem this code.....

Any one help me.

Thanks in advance.
Posted
Updated 11-Sep-12 23:25pm
v4
Comments
bbirajdar 12-Sep-12 5:12am    
Not clear..Where do you want to typecast ? Show your code where you are facing the problem..
Shambhoo kumar 12-Sep-12 5:16am    
in windows application(2008)...
Shambhoo kumar 12-Sep-12 5:19am    
CheckBox asa = (CheckBox)dataGridview1.Rows[1].Cells[3];

this field is allready datagridviewchechkboxcolumn

Hi,

The cells in the DataGidViewCheckBoxColumn are of type DataGirdViewCheckBoxCell. So, you cannot cast directly DataGirdViewCheckBoxCell to checkbox. instead you can use DataGirdViewCheckBoxCell itself.

refer this link for more on DataGirdViewCheckBoxCell.

Set DataGridViewCheckBoxCell Value to True[^]
DataGridViewCheckBoxCell Class[^]

Hope it helps.
 
Share this answer
 
v3
Hi,
Why you want to typecast that? You can directly fetch the value.
Try this:
C#
foreach (DataGridViewRow dataGridRow in dataGridView1.Rows)
{
   if (dataGridRow.Cells["YourCheckboxColumn"].Value != null &&    (bool)dataGridRow.Cells["YourCheckboxColumn"].Value)
  {
         // Checked
  }
  else if (dataGridRow.Cells["YourCheckboxColumn"].Value == null)
  {
         // Unchecked
  }
}



--Amit
 
Share this answer
 
Comments
Shambhoo kumar 13-Sep-12 2:57am    
Thanks Brother.......
:)

Regard
Sham
_Amy 13-Sep-12 2:59am    
Always welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900