Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have a datagridview with a combobox coloumn. A few items have veen added to it. (Say Furniture, Property etc.)

I wish when I select Property, the column 2 of my current row should get text Property.

Which even to be fired for this. I tried _CellValueChanged etc. but they did not work.

Thanks
Furqan
Posted

Unfortunately there are no events for that.
Here are a few workaround events:
1. CellEndEdit Event:
But its only fired when leaving the cell
2. CurrentCellDirtyStateChanged event:
Immediately fires upon change, but only for the first change. if you stay in the cell & keep changing checkstate, you will not receive the event after the first change. Event is once more fired when cell is left.
3. Use the CellContentClick event: It's most appropriate. Fires when checkstate is changed.

Note that all these events are fired for all types of columns & not just checkbox columns. So on event, you should check the column type & then check the state.
 
Share this answer
 
You can sort of add the event you are looking for with two methods. The first one will add the the event whenever the user accesses the cell for editing:
VB
Private Sub gvMast_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles gvMast.EditingControlShowing
'This event will setup an event handler for the
'Status combobox column in the grid
'and activate that event handler for the selected combobox.

        Dim cboTemp As ComboBox = CType(e.Control, ComboBox)
        'Remove the handler before adding it to ensure that
        'the event will only be run once
        RemoveHandler cboTemp.SelectionChangeCommitted, AddressOf StatusComboBox_SelectionChangeCommitted
        'Add the handler to the StatusComboBox_SelectionChangeCommitted
        'method, this method will ensure
        'that the event will only be called after the user
        'has selected a different code from the
        'databound status combobox column
        AddHandler cboTemp.SelectionChangeCommitted, AddressOf StatusComboBox_SelectionChangeCommitted

    End Sub


The second will perform the task you wanted to put in the selection change event and must have the same name as the AddressOf method you point to in the first one:

VB
Private Sub StatusComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)

    'Add code here to reset your column 2 the way you want

End Sub


---EDIT---
I forgot to mention that inside that second method you haven't yet changed the cell value...so if you want the old value of the cell you would get it like this:
Dim strCurrentMastStatus As String = gvMast.SelectedRows(0).Cells(strColumnName).Value


And to access the NEW value that the user has selected you would use this:
Dim cboTemp As ComboBox = CType(sender, ComboBox)
cboTemp.SelectedValue
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900