473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 6877
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

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

Similar topics

2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
4
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv,...
4
by: Annie | last post by:
hello guys, I am having a DataGridView control. The first column is a checkbox column. The users can select the checkbox column. I need to loop through the grid rows and get the checked...
2
by: mrstrong | last post by:
Gday, I have a datagridview that I am creating the columns programatically which all seems to work fine. I have a couple of dropdown boxes, so I have set the editMode= EditOnEnter. Now my...
2
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
1
by: zacks | last post by:
Using VS 2005. I have an app that has a DataGridView control. This control has two columns, the first column is a standard TextBox, and the second column is a CheckBox. I am having difficulty...
1
by: QuickBooksDev | last post by:
VB.NET 2005 DataGridView Checkbox - Check Event need to know check status I would like to use the DataGridView Checkbox like a normal checkbox. When someone clicks on it I would expect that I...
0
by: tramesh2007 | last post by:
I am using datagridviewcheckbox column in datagridview. I have a probelm for clicking checkbox column. The problem is, On datagrid_CellMouseClick event, for clicking checkbox when getting...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
If I populate a DataGridView with a query supplied at runtime, boolean fields render as a CheckBox instead of just a text rendering of '0' or '1'. That is nice sometimes, but I would like the...
0
by: =?Utf-8?B?S2lt?= | last post by:
Hi all I'm working with a column of checkbox in datagridview. I can mark the cells defalut false 1. time by set thristate to false and varpmode to false too => all the cell are default false...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.