Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > VS2005: Inherited Base forms and control event issues
 

VS2005: Inherited Base forms and control event issues

I am building a new application in VS2005 and I am using form inheritance since it saves me a lot of development time (ok, kinda- sorta). In my base form, I have a ComboBox control and New, Save, Delete and Undo buttons. The combobox is bound to a dataset and the SelectedIndexChanged event is overridden in the inheritance form.

Base Form:

Public Overridable Sub cbSelectItem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSelectItem.SelectedIndexChanged

If Not bNewRow Then

Me.StaffBindingSource.Position = Me.cbSelectItem.SelectedIndex

End If

End Sub

Inheritance Form:

Public Overrides Sub cbSelectItem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSelectItem.SelectedIndexChanged

'Excute the base class method

If Not MyBase.cbSelectItem.SelectedIndex = -1 Then

MyBase.cbSelectItem_SelectedIndexChanged(Me, e)

Me.LoadBindStaffAffiliationTable()

End If

End Sub

Here is the ugly wrinkle: For some reason, the SelectedIndexChanged event is executed twice for any single click of the combo box AND this is true for any singleClick event of New, Save, Delete or Undo. It's as though the Base form is causing this problem but I cannot put my finger on it. Every control is fired twice.

Does anyone have a pointer as to where to look first in order to resolve this problem? I have to believe it's form inheritance causing my problem but I don't recall this problem with form inheritance in VS2003.

VBProEd  Friday, December 14, 2007 8:42 PM
I just figured it out. When using form inheritance, the "Handles cbSelectItem.SelectedIndexChanged" needs to be removed on the form using inheritance. Click events now only fire once.
VBProEd  Saturday, December 15, 2007 11:58 PM
I just figured it out. When using form inheritance, the "Handles cbSelectItem.SelectedIndexChanged" needs to be removed on the form using inheritance. Click events now only fire once.
VBProEd  Saturday, December 15, 2007 11:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Access Checked Items in Databound Checked ListBox
• linking checkbox to the database
• Which forum for: reducing the size of an icon.
• Dataset problem
• ComboBox fill with foreach or BindingSource
• How do you update automatically created strongly-typed datasets in VS2005?
• dataGridView: nested obj., masked input
• Inserting multiple rows from datagrid to database
• Databinding to Combobox
• datagrid odbc