469,352 Members | 2,214 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

DataGridView CheckBox

Hi,

I have a Checkbox column in the DataGridView.

I am unable to change the state of the checkbox.

Why is this??? What do I need to set in Properties?

Using Visual Studio 2005

Thanks.
Jul 17 '07 #1
9 6657
can anyone please help? Thank you!
Jul 17 '07 #2
Plater
7,872 Expert 4TB
What is the code you are using?
Is the column marked readonly(default)?
Are you bound to a datasource?

Please provide more information.
Jul 17 '07 #3
What is the code you are using?
Is the column marked readonly(default)?
Are you bound to a datasource?

Please provide more information.
I am bound to a datasource.
Column is not readonly.
The value it is bound to is an integer. Should it be boolean??

Tried binding to nothing and same issue.

Thanks.
Jul 17 '07 #4
Plater
7,872 Expert 4TB
If you are bound to a datasource you shouldn't be able to change the column type. It should be auto-created based on the underlying type from the datasource.

But yes, checkboxes should only be used to booleans
Jul 17 '07 #5
But I need to be able to allow the user to check/uncheck any row item.

Their selection will be saved to a database using a id related to the other columns in the datagridview.

Any suggestions??
Jul 17 '07 #6
OK I am able to Check/Uncheck an unbound DGV CheckBox. Set Read-Only to false.

I want to bind the primary key of my table to the checkbox.
If I do this then I am unable to check/uncheck the checkbox.

Any ideas?

Thanks
Jul 18 '07 #7
This code works for me provided the user only checks the checkbox once...

How Do I ensure the ArrayList only adds when the checkbox is at checked state??

Thanks!!

Expand|Select|Wrap|Line Numbers
  1. private void counterPartyDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2.         {
  3.             DataGridView dgv2 = sender as DataGridView;
  4.  
  5.             if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
  6.             {
  7.                 ArrayList mySelectionArray = new ArrayList();
  8.  
  9.                 if (e.ColumnIndex == 0)
  10.                 {
  11.                     DataRow dr2 = ((DataRowView)dgv2.Rows[e.RowIndex].DataBoundItem).Row;
  12.  
  13.                     int mySelection2 = (int)dr2[dgv2.Columns[1].DataPropertyName]; // 1 = unique id column
  14.                     mySelectionArray.Add(mySelection2);
  15.                 }
  16.             }
  17.         }
Jul 18 '07 #8
Plater
7,872 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. if (mycheckbox.Checked==true)
  2. {
  3. }
  4.  
Jul 18 '07 #9
Expand|Select|Wrap|Line Numbers
  1. if (mycheckbox.Checked==true)
  2. {
  3. }
  4.  
The Checked function is not available here...

Expand|Select|Wrap|Line Numbers
  1. private void counterPartyDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2.         {
  3.             DataGridView dgv2 = sender as DataGridView;
  4.  
  5.             if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
  6.             {
  7.                 //ArrayList mySelectionArray = new ArrayList();
  8.  
  9.                 if (e.ColumnIndex == 0)
  10.                 {
  11.                     DataRow dr2 = ((DataRowView)dgv2.Rows[e.RowIndex].DataBoundItem).Row;
  12.  
  13.                     foreach (DataGridViewCheckBoxColumn thisCheckBox in dgv2.Columns)
  14.                     {
  15.                         if (thisCheckBox.Selected = CheckState.Checked)
  16.                         {
  17.                             int mySelection2 = (int)dr2[dgv2.Columns[1].DataPropertyName]; // 1 = unique id column
  18.                             mySelectionArray.Add(mySelection2);
  19.                         }
  20.                     }
  21.  
  22.                     //int mySelection2 = (int)dr2[dgv2.Columns[1].DataPropertyName]; // 1 = unique id column
  23.                     //mySelectionArray.Add(mySelection2);
  24.                 }
  25.             }
  26.         }
Jul 23 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Rick Shaw | last post: by
2 posts views Thread by mrstrong | last post: by
2 posts views Thread by mrstrong | last post: by
1 post views Thread by zacks | last post: by
reply views Thread by tramesh2007 | last post: by
8 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.