473,387 Members | 1,440 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,387 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 2120
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.