RE: Tab Control and Combo Box (bound) by MycGyver
MycGyver
Fri Oct 21 16:10:03 CDT 2005
I'm having the same problem. Did you find a solution David?
Below is some sample code to produce the problem.
Add Tab control to form.
Add 2 Tabs to tabcontrol.
Add Combo to tab
Paste the following code into form:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim aStatus() As Status = {New Status("OPN", "Open"), New
Status("CLS", "Closed")}
ComboBox1.DataSource = aStatus
ComboBox1.DisplayMember = "StatusName"
ComboBox1.ValueMember = "StatusCode"
'Clear selection.
ComboBox1.SelectedIndex = -1
End Sub
End Class
Public Class Status
Private m_strStatusCode As String
Private m_strStatusName As String
Public ReadOnly Property StatusCode() As String
Get
StatusCode = m_strStatusCode
End Get
End Property
Public ReadOnly Property StatusName() As String
Get
StatusName = m_strStatusName
End Get
End Property
Sub New(ByVal StatusCode As String, ByVal StatusName As String)
m_strStatusCode = StatusCode
m_strStatusName = StatusName
End Sub
End Class
"David" wrote:
> I have a combo box that is on a tab page in the tab control. The combo box
> is bound to a dataset - I already know about the problem of having to set the
> selected index twice to set it at -1. At runtime, when I go to another tab
> page, the selected index is still at -1, but when I go back to the first tab
> page where the combo box is, the selected index of the combo box is set back
> to 0, and there is text in the combo box. The SelectedIndexChanged event
> does NOT fire. Does anybody have a workaround for this?