|
-
Oct 3rd, 2011, 02:52 PM
#1
Thread Starter
Member
[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
-
Oct 3rd, 2011, 08:56 PM
#2
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.
-
Oct 4th, 2011, 03:58 AM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|