Discussion:
Editing cells in a DataGridView
(too old to reply)
Thomas
2007-06-12 19:36:36 UTC
Permalink
How do you apply formatting to edited cells in a datagridview? I want
to allow the user to type text in either upper or lowercase but after
their edit is complete, I need to shift the value to uppercase.

Here's what I doing:

Private Sub dgridviewAppSettings_CellValueChanged(ByVal sender As
Object, ByVal e As DataGridViewCellEventArgs) Handles
dgridviewAppSettings.CellValueChanged

dgridviewAppSettings.CurrentCell().Value =
dgridviewAppSettings.CurrentCell().Value.ToString().ToUpper

End Sub

This works but the event is fired twice since I'm programmatically
editing the cell after the user does. Is there a way to prevent this?

TIA,
Thomas
Atif Shehzad
2011-07-13 02:33:19 UTC
Permalink
I know its and old old thread, but I am posting for good (in case some1 looks for it same as I could not figure a solution to a similar problem of firing an event twice).
I suggest use CellEndEdit event instead.
CellValueChanged is fired once when user enters a value and second time when you change the value to update it.
Post by Thomas
How do you apply formatting to edited cells in a datagridview? I want
to allow the user to type text in either upper or lowercase but after
their edit is complete, I need to shift the value to uppercase.
Private Sub dgridviewAppSettings_CellValueChanged(ByVal sender As
Object, ByVal e As DataGridViewCellEventArgs) Handles
dgridviewAppSettings.CellValueChanged
dgridviewAppSettings.CurrentCell().Value =
dgridviewAppSettings.CurrentCell().Value.ToString().ToUpper
End Sub
This works but the event is fired twice since I'm programmatically
editing the cell after the user does. Is there a way to prevent this?
TIA,
Thomas
Loading...