Results 1 to 4 of 4

Thread: [02/03] Databinded Combobox Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    48

    [02/03] Databinded Combobox Problem

    Hey,

    I have a combobox databinded with a dataset and every works great and whatnot. The problem I'm having is that when the form loads, the text of the combobox is the first item in the list. I want it blank and the code

    VB Code:
    1. combobox.selectedindex = -1

    doesn't work. Neither does setting the Text property to blank. Does anybody know how to do this??

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: [02/03] Databinded Combobox Problem

    Quote Originally Posted by r_barlow
    Hey,

    I have a combobox databinded with a dataset and every works great and whatnot. The problem I'm having is that when the form loads, the text of the combobox is the first item in the list. I want it blank and the code

    VB Code:
    1. combobox.selectedindex = -1

    doesn't work. Neither does setting the Text property to blank. Does anybody know how to do this??
    Hi,

    Try setting the SelectedIndex twice. There is a known bug for which that is the workaround. A search of the Microsoft Knowledge Base will provide more information if you're interested. (posted by jmcilhinney)

    Hope it helps for you,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    48

    Re: [02/03] Databinded Combobox Problem

    Thanks for the tip!! That seems to work when responding to a control event (button click for example) but not for the Form_Load event which is what I'm trying to accomplish. Any other suggestions?

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: [02/03] Databinded Combobox Problem

    Quote Originally Posted by r_barlow
    Hey,

    I have a combobox databinded with a dataset and every works great and whatnot. The problem I'm having is that when the form loads, the text of the combobox is the first item in the list. I want it blank and the code
    doesn't work. Neither does setting the Text property to blank. Does anybody know how to do this??
    Hi,

    I've created something, you could try it.
    Set the Text property to blank.

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim Objects(20) As DataItem
    3.         ComboBox1.BeginUpdate()
    4.         Dim intLoopIndex As Integer
    5.         For intLoopIndex = 0 To 20
    6.             Objects(intLoopIndex) = New DataItem("Item " & intLoopIndex, CSng(intLoopIndex))
    7.             'ComboBox1.Items.Add(Objects(I))
    8.         Next
    9.         ComboBox1.Items.AddRange(Objects)
    10.         ComboBox1.EndUpdate()
    11.     End Sub
    12.  
    13.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    14.         MsgBox("Your selected item: " & CType(ComboBox1.SelectedItem, DataItem).GetData())
    15.     End Sub
    16. End Class
    17.  
    18. Public Class DataItem
    19.     Private Data As Single
    20.     Private Name As String
    21.     Public Sub New(ByVal NameArgument As String, ByVal Value As Single)
    22.         Name = NameArgument
    23.         Data = Value
    24.     End Sub
    25.  
    26.     Overrides Function ToString() As String
    27.         Return CStr(Name)
    28.     End Function
    29.  
    30.     Public Function GetData() As Single
    31.         Return Data
    32.     End Function
    33. End Class

    I hope it helps,

    sparrow1
    Last edited by sparrow1; Apr 9th, 2006 at 03:08 AM.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

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