Results 1 to 3 of 3

Thread: Strange ComboBox Bug

  1. #1

    Thread Starter
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Strange ComboBox Bug

    I'm Every one

    I've create a function That help me fill my combobox's, like this:

    VB Code:
    1. Public Sub FillComboBox(ByVal pCombo As System.Windows.Forms.ComboBox, ByVal pAccesBD As clsAccesDBSQL, ByVal pSQLQuery As String)
    2.  
    3.         Dim dt As DataTable
    4.         dt = pAccesBD.GetDataSet(pSQLQuery).Tables(0)
    5.         pCombo.DataSource = dt
    6.  
    7.         If dt.Rows.Count > 0 Then
    8.  
    9.             pCombo.BeginUpdate()
    10.  
    11.             pCombo.ValueMember = dt.Columns(0).ToString
    12.             pCombo.DisplayMember = dt.Columns(1).ToString
    13.  
    14.             pCombo.EndUpdate()
    15.  
    16.         End If
    17.  
    18.         pCombo.SelectedIndex = -1
    19.     End Sub

    My filled ComboBox, is on a TabControl on a Form, and when I switch to the second Tab and come back to the first tab, the First Item in my ComboBox is selected !?!? , I've absolutly no code "behind" that do so, and if I look to the SelectedIndex Before the tab switf it equal -1 after it's equal to 0

    Do somebody can help ...

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: Strange ComboBox Bug

    dunno if this satisfies on what you seek, but as i observe about combobox the selected index value = 0 is the default, so you need to do some trapping about it, by adding this.
    VB Code:
    1. Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    2.         If Me.TabControl1.SelectedIndex = 0 Then
    3.             Me.ComboBox1.SelectedIndex = -1
    4.         End If
    5.     End Sub
    or maybe there's another way that i dunno hehehe.
    cheers.

  3. #3

    Thread Starter
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: Strange ComboBox Bug

    Emmm it can be a solution, but it do not fix the bug ..
    Last edited by Zakary; Mar 18th, 2005 at 08:13 AM. Reason: Message Syntax error

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