473,287 Members | 1,419 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,287 software developers and data experts.

DataGridView - Not much doc out there

22 16bit
Can anyone tell me how I can tell if a checkbox in a DataGridView (I call it DGV1) is checked? When I click one box, I get to the DGV1_CellClick event. From there, I am lost. A lot of the examples show a foreach, but I am not processing ALL of the rows. I just want to look at the ONE cell in ONE column and ONE row, and see if it is the one that was clicked/checked. In other words, the click of WHICH checkboxbox caused this event to trigger?
Any help would be greatly appreciated!
Dave
May 4 '21 #1

✓ answered by SioSio

Use the DataGridView.CellValueChanged event to know that the checkbox is checked (or unchecked). However, the CellValueChanged event is fired when the value is committed, such as by moving the focus to another cell after the checkbox is checked. To have the CellValueChanged event fire immediately after the checkbox is checked, call the DataGridView.CommitEdit method in the CurrentCellDirtyStateChanged event handler to commit the value.
Expand|Select|Wrap|Line Numbers
  1.         //CurrentCellDirtyStateChanged Event Handler
  2.         private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  3.         {
  4.             if (dataGridView1.CurrentCellAddress.X == 0 && dataGridView1.IsCurrentCellDirty)
  5.             {
  6.                 //Commit
  7.                 dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
  8.             }
  9.         }
  10.  
  11.         //CellValueChanged Event Handler
  12.         private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  13.         {
  14.                 MessageBox.Show(
  15.                     string.Format("The value of the checkbox in the row[{0}] has changed to {1}.",
  16.                               e.RowIndex,dataGridView1[e.ColumnIndex, e.RowIndex].Value));
  17.         }

1 2114
SioSio
272 256MB
Use the DataGridView.CellValueChanged event to know that the checkbox is checked (or unchecked). However, the CellValueChanged event is fired when the value is committed, such as by moving the focus to another cell after the checkbox is checked. To have the CellValueChanged event fire immediately after the checkbox is checked, call the DataGridView.CommitEdit method in the CurrentCellDirtyStateChanged event handler to commit the value.
Expand|Select|Wrap|Line Numbers
  1.         //CurrentCellDirtyStateChanged Event Handler
  2.         private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  3.         {
  4.             if (dataGridView1.CurrentCellAddress.X == 0 && dataGridView1.IsCurrentCellDirty)
  5.             {
  6.                 //Commit
  7.                 dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
  8.             }
  9.         }
  10.  
  11.         //CellValueChanged Event Handler
  12.         private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  13.         {
  14.                 MessageBox.Show(
  15.                     string.Format("The value of the checkbox in the row[{0}] has changed to {1}.",
  16.                               e.RowIndex,dataGridView1[e.ColumnIndex, e.RowIndex].Value));
  17.         }
May 6 '21 #2

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

Similar topics

3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
1
by: David | last post by:
can anybody help about this subject??? I have to hide some columns with visible=false but I need their value. With a gridview in a website I used datakeys, but with a datagridview there are no such...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
1
by: Karl | last post by:
Hi all... This is a good one. You'll like this... I am working on a course management tool that allows certain Courses to be cross referenced with Job Roles and, when they are, whether the...
4
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I use unbound DataGridView controls in my form (simply because I have to manually message my data before populating the DataGridView with it). Say I clear all the info from the DataGridView: ...
0
by: priyamtheone | last post by:
There's an editable datagridview populated from a table say tblItems. Among the columns of the datagridview there's a combobox column named 'Category'. This column is populated by the respective...
0
by: Levent Akkoyunlu | last post by:
Hello, I have a problem with datagridview.There are 5 colums which one of them has line number from 1 to 10 and others have checkboxes in it. The Problems is : If A user selects one checkbox and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.