Results 1 to 3 of 3

Thread: [RESOLVED] DataGridView Comboboxes

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    48

    Resolved [RESOLVED] DataGridView Comboboxes

    Hi I have problem with a datagridview with combo boxes firing unwanted events handlers.

    I have a datagridview with 4 columns all data bound. All of these columns have comboboxes. Column 2,3,4 has a custom generated combobox with code with on the 'DataGridView_EditingControlShowing event' and have event handlers (Dropdown,selected Etc). (Data in the custom generated comboboxes needs to be filtered and worked on)

    Code:
     
    
    Friend WithEvents ComboBoxPowerPlantSelect As System.Windows.Forms.ComboBox
        Friend WithEvents ComboBoxAttachment1 As System.Windows.Forms.ComboBox
        Friend WithEvents ComboBoxAttachment2 As System.Windows.Forms.ComboBox
    
    Private Sub TblMachineCombinationListDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles TblMachineCombinationListDataGridView.EditingControlShowing
    
            Select Case ColumnSelected
                Case 3 : ComboBoxPowerPlantSelect = TryCast(e.Control, ComboBox) 'generate the combobox
                    MachinePowerPlantSelected()
                Case 4 : ComboBoxAttachment1 = TryCast(e.Control, ComboBox)       'Generate the combobox
                    Attachment1Selected()
                Case 5 : ComboBoxAttachment2 = TryCast(e.Control, ComboBox)       'Generate the combobox
                    Attachment2Selected()
                Case Else : Exit Sub
            End Select
    
        End Sub
    The problem is if i select a column with a combobox (Col 2 or 3 or 4) that i have generated THEN select a column on the datagrid that i have not generated Col 1 the event handler (Dropdown) from the previous generated combobox is fired.
    How do i stop this, or what is the best way of disposing of the previously used combobox that i have generated after the user has selected the data in the combobox.
    I don't know where to put the ComboBoxPowerPlantSelect.dispose() method to handle this properly in my code

    Cheers

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataGridView Comboboxes

    You don't dispose anything. Handle the CellEndEdit event of the grid and set all those WithEvents variables to Nothing, thus removing all the event handlers.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    48

    Thumbs up Re: DataGridView Comboboxes

    Thanks for that small nugget. Works well

Tags for this Thread

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