samedi 28 mars 2015

Get Current Cell Value in EditingControlShowing


Vote count:

0




What I'm trying to do is, if I type "red" into a cell, then the cell's backcolor changes to red and if I type "blue" into a cell, then the cell's backcolor changes to blue. The problem I'm getting is, if I type "blue", only "blu" is recorded as mystring, as the textchanged event records the cell value before the change, so the cell's backcolor never changes color as a result. I hoping someone might have an idea on how to get the current cell value after a textcahnge. My current code below (this is just an example). Any idea or help will be appreciated, thanks.



Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
Me.DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End Sub

Dim EditingControl As DataGridViewTextBoxEditingControl

Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing

EditingControl = e.Control
AddHandler EditingControl.TextChanged, AddressOf EditingControl_TextChanged

End Sub

Private Sub EditingControl_TextChanged(sender As Object, e As EventArgs)

mystring = Me.DataGridView1.CurrentCell.Value
If mystring = "red" Then
EditingControl.BackColor = Color.Red
ElseIf mystring = "blue" Then
EditingControl.BackColor = Color.Blue
Else
EditingControl.BackColor = Color.White
End If

End Sub


asked 39 secs ago







Get Current Cell Value in EditingControlShowing

Aucun commentaire:

Enregistrer un commentaire