Geeks With Blogs
Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done

 

private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)

        {

            try

            {

                int row = e.RowIndex;

                int col = e.ColumnIndex;

                if (dgv.CurrentCell is System.Windows.Forms.DataGridViewCheckBoxCell)

                {

 

                    DataGridViewCell cell = dgv.CurrentCell;

 

                    DataGridViewCheckBoxCell checkCell =

                        (DataGridViewCheckBoxCell)dgv.Rows[row].Cells[col];

 

                    //------------------------------------------------------------------

                    //

                    //------------------------------------------------------------------

                    bool newBool = (bool) checkCell.EditingCellFormattedValue;

                    bool originalBool = !newBool;

                    string originalValue = originalBool.ToString();

                    string newValue = newBool.ToString();

                }

 

            }

            catch (Exception ex)

            {

            }

        }

 

    Private Sub dgv_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgv.CurrentCellDirtyStateChanged

        '--------------------------------------------------------

        'when a user checks/unchecks a checkbox

        'perform "commitEdit" so that "CellValueChanged" event gets fired

        '--------------------------------------------------------

        If dgv.IsCurrentCellDirty Then

            dgv.CommitEdit(DataGridViewDataErrorContexts.Commit)

        End If

 

    End Sub

 

    Private Sub dgv_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellValueChanged

 

        '--------------------------------------------------------

        'when a user checks/unchecks a checkbox

        'be sure to check/uncheck other rows with same session, barcode and assay (but different seq)

        '--------------------------------------------------------

        Dim checked As Boolean = Boolean.Parse(dgv.CurrentRow.Cells(gCol.PlateIsLabeled).Value.ToString) = True

        Dim targetSessionName As String = dgv.CurrentRow.Cells(gCol.SessionName).Value.ToString

        Dim targetPlateBarcode As String = dgv.CurrentRow.Cells(gCol.PlateBarcode).Value.ToString

        Dim targetAssayName As String = dgv.CurrentRow.Cells(gCol.AssayName).Value.ToString

        For Each irow As DataGridViewRow In dgv.Rows

            If irow.Index <> dgv.CurrentRow.Index Then

                Dim PlateBarcode As String = irow.Cells(gCol.PlateBarcode).Value.ToString

                Dim AssayName As String = irow.Cells(gCol.AssayName).Value.ToString

                Dim SessionName As String = irow.Cells(gCol.SessionName).Value.ToString

                If PlateBarcode = targetPlateBarcode _

                And AssayName = targetAssayName _

                And SessionName = targetSessionName _

                Then

                    irow.Cells(gCol.PlateIsLabeled).Value = checked

                End If

            End If

        Next

 

    End Sub

Capture DataGridView CheckBox Checked event on a WinForm

Posted on Wednesday, April 13, 2011 11:19 AM GridView, Datagrid, DataList & Repeater | Back to top


Comments on this post: Capture DataGridView CheckBox Checked event on a WinForm

# re: Capture DataGridView CheckBox Checked event on a WinForm
Requesting Gravatar...
Thank You, my headache is gone!!
This is the solution i was lookng for.

My error was in using BeginEdit and EndEdit
Aditional, I was wrong in capture the refence to the current checkbox.
Left by Alberto on Jun 13, 2012 10:27 PM

# re: Capture DataGridView CheckBox Checked event on a WinForm
Requesting Gravatar...
so good,very useful.
Left by Jordan Shoes on Mar 02, 2013 12:30 AM

# re: Capture DataGridView CheckBox Checked event on a WinForm
Requesting Gravatar...
Very good...
thank you....it helped a lot
Left by vijay on Apr 22, 2013 7:07 AM

# re: Capture DataGridView CheckBox Checked event on a WinForm
Requesting Gravatar...
'gCol' is not declared. It had not mentioned gCol what was.
Left by Sinan on Apr 25, 2013 10:51 PM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net