Note that there are some explanatory texts on larger screens.

plurals
  1. POvb.net, combobox.datasource will change selected index?
    primarykey
    data
    text
    <p>Let me try to describe my problems in the simplest way: I have combobox1 and combobox2. I hope to achieve two things:</p> <ol> <li><p>Combox1 is bound to list1 (a list of string). When a user selects an item in list1, list2 (a list of string) will be obtained from database and combobox is bound to list2.</p></li> <li><p>If user specifies text1 in combobox1 and text2 in combobox2, then these two values will be shown in the comboboxes regardless of the bound lists.</p></li> </ol> <p>So I set DropDown as dropdpwnstyle to both comboboxes.</p> <pre><code>Public Sub New(Optional ByVal text1 As String = "", Optional ByVal text2 As String = "") ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.combobox1.selectedText=text1 Me.combobox2.selectedText=text2 End Sub Private Sub Form_Load(sender As Object, e As System.EventArgs) Handles Me.Load BindComboBox1() End Sub Private Sub BindComboBox1() 'm_list1 is a list of string combobox1.DataSource = m_list1 End Sub Private Sub GetCombobox2() 'based on the selected item in combobox1, m_list2 which is a list of string is obtained ComboBox2.DataSource = m_list2 End Sub Private Sub combobox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles combobox1.SelectedIndexChanged If combobox1.SelectedIndex &lt;&gt; -1 Then GetCombobox2() End If End Sub </code></pre> <p>When I debug, I notice two things:</p> <ol> <li><p>After Me.combobox1.SelectedText=text1, actually, Me.combobox1.SelectedText="". But Me.combobox1.Text=text1. Is this because combobox1.SelectedIndex=-1?</p></li> <li><p>Combobox1.datasource=m_list1 changes combobox1.selectedindex from -1 to 0. This will fire the combobox.selectedIndexchange event.</p></li> </ol> <p>So the results of above code is that goal 1 is achieved, but goal 2 is never achieved. combobox1.selected index is always 0 and combobox2.selected index is always 0 too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload