Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDetect changes to the editing text when the user changes a DataGridView's data in Visual Basic 2005
DescriptionThis example shows how to detect changes to the editing text when the user changes a DataGridView's data in Visual Basic 2005.
KeywordsDataGridView, edit, edit cell, TextChanged, Visual Basic 2005, VB 2005
CategoriesControls, VB.NET
 
Create a WithEvents variable of type DataGridViewTextBoxEditingControl. In the DataGridView's EditingControlShowing event handler, set this variable to the editing control.
 
Private WithEvents m_EditingControl As _
    DataGridViewTextBoxEditingControl

' Set the editing control so we can catch its events.
Private Sub DataGridView1_EditingControlShowing(ByVal _
    sender As Object, ByVal e As _
    System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) _
    Handles DataGridView1.EditingControlShowing
    Debug.WriteLine("Editing")
    m_EditingControl = e.Control
End Sub
 
Now you can catch the editing control's events. For example, the following code catches the TextChanged event and displays the current text as the user types it.
 
' Unset the editing control so we no longer catch its
' events.
Private Sub m_EditingControl_LostFocus(ByVal sender As _
    Object, ByVal e As System.EventArgs) Handles _
    m_EditingControl.LostFocus
    m_EditingControl = Nothing
    Debug.WriteLine("Done")
End Sub
 
When the editing control loses focus, set the variable to Nothing so you no longer catch the editing control's events.
 
' Catch the editing control's TextChanged event.
Private Sub m_EditingControl_TextChanged(ByVal sender As _
    Object, ByVal e As System.EventArgs) Handles _
    m_EditingControl.TextChanged
    Dim ctl As DataGridViewTextBoxEditingControl = _
        DirectCast(sender, _
            DataGridViewTextBoxEditingControl)
    Debug.WriteLine(ctl.Text)
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated