DataGridView checkbox column problem
-
I want to display some invoice details in a datagridview (dgv). I want the user to be able to click a check box, which I've added to the dgv, so that they can indicate whether they want the invoice amount or invoice total to be used in calculations on that invoice. There are boolean properties called UseInvAmount and UseInvTotal in the invoice object. I can get the check box to appear in the grid okay, but clicking on it does not make a check appear, even though the cellContentClick sub fires when the checkBox cell is clicked. I've got code that handles the 2 events: cellValueNeeded & cellValuePushed, and I've also added 2 event handlers to the dgv (DataGridViewCellEventHandler & DataGridViewRowsAddedEventHandler) and registered the dgv's "with events", but the cellValueNeeded and cellValuePushed code are not triggered by clicking on the checkboxes. Can anyone tell me what I've left out or how to make a checkbox click on & off, and work independently of another one? Pauki
-
I want to display some invoice details in a datagridview (dgv). I want the user to be able to click a check box, which I've added to the dgv, so that they can indicate whether they want the invoice amount or invoice total to be used in calculations on that invoice. There are boolean properties called UseInvAmount and UseInvTotal in the invoice object. I can get the check box to appear in the grid okay, but clicking on it does not make a check appear, even though the cellContentClick sub fires when the checkBox cell is clicked. I've got code that handles the 2 events: cellValueNeeded & cellValuePushed, and I've also added 2 event handlers to the dgv (DataGridViewCellEventHandler & DataGridViewRowsAddedEventHandler) and registered the dgv's "with events", but the cellValueNeeded and cellValuePushed code are not triggered by clicking on the checkboxes. Can anyone tell me what I've left out or how to make a checkbox click on & off, and work independently of another one? Pauki
i cannot understand your requirement fully pauki.the event CellValueChanged is fired after a checkbox is checked.but before handling that event u have to handle one more even ie CurrentCellDirtyStateChanged.i have given that code below Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged Try If DataGridView1.IsCurrentCellDirty Then DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If Catch ex As Exception End Try End Sub after that handle the event CellValueChanged like this If e.RowIndex > 0 Then If DataGridView1.Item(0, e.RowIndex).Value Then MsgBox("hello") End If End If if u need more explantion reply:rose:
shally
-
i cannot understand your requirement fully pauki.the event CellValueChanged is fired after a checkbox is checked.but before handling that event u have to handle one more even ie CurrentCellDirtyStateChanged.i have given that code below Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged Try If DataGridView1.IsCurrentCellDirty Then DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If Catch ex As Exception End Try End Sub after that handle the event CellValueChanged like this If e.RowIndex > 0 Then If DataGridView1.Item(0, e.RowIndex).Value Then MsgBox("hello") End If End If if u need more explantion reply:rose:
shally
thanx Shally, I did actually try this code too, and altho it fired, I was still bothered by the fact that it didn't automatically set the check in the box (I guess I could try to set the value in the checkbox, but instead I tried using 1 unbound checkbox, useInvTotal, rather than the 2 bound boolean properties, and that seemed to work). I can't believe that it's so complicated just to get a checkbox to write back to the db - (i.e. cellContentClick is also fired on clicking a cell, and all this need for cellValueNeeded, cellValuePushed etc. to set the initial values...) I'll see if I can get your suggestion to work anyway. thanks again, PK