CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    239

    [RESOLVED] DataGridViewComboBoxColumn change to automatically update DataGridView

    I have a standard DataGridView. One of the columns is a DataGridViewComboBoxColumn. When I select one of the ComboBox items, I want to trap the change and add additional columns based on the item selected in the ComboBox. I've tried using CellValueChanged for the DataGridView column, and a bunch of other events, but none of them is fired when the DataGridViewComboBox value is changed. What event can I trap to make this happen? Right now as I said, I am using CellValueChanged, but of course the event doesn't fire until I click on another cell...

  2. #2
    Join Date
    Nov 2004
    Posts
    239

    Smile Resolved: DataGridViewComboBoxColumn change to automatically update DataGridView

    Here's what I had to end up doing:

    Code:
        Private Sub dgvClass_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvClass.EditingControlShowing
            If TypeOf e.Control Is ComboBox Then
                Dim combo As ComboBox = DirectCast(e.Control, ComboBox)
    
                If combo IsNot Nothing Then
                    RemoveHandler combo.SelectedIndexChanged, _
                    New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
    
    
                    AddHandler combo.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged
                End If
            End If
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured