Results 1 to 5 of 5

Thread: [2005] Simple Combobox problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    73

    [2005] Simple Combobox problem

    I just want to add each combobox item into a Toolstrip ComboBox. The next sourcecode will not work:


    Code:
        Private Sub CopyBoxItems()
    
            Me.ToolStripBox.Items.Clear()
    
            For i As Integer = 0 To FilterBox.Items.Count - 1
    
                Me.ToolStripBox.Items.Add(Me.FilterBox.Items.Item(i))
    
            Next
    
        End Sub
    Last edited by fatihpk; Aug 17th, 2007 at 09:33 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Simple Combobox problem

    What error do you get?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    73

    Re: [2005] Simple Combobox problem

    The box is filled with

    System.Data.Datarow etc.

    I just can't loop through the Filter Box.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Simple Combobox problem

    You're adding items directly from your FilterBox to the ToolStripBox. If your FilterBox is bound to a DataTable then each of those items is a DataRow, so it's no surprise that that's what you see in the ToolStripBox. If you only want to add the text of each item in the FilterBox to the TooStripBox then that's exactly what you have to do:
    vb.net Code:
    1. For Each item As Object In FilterBox.Items
    2.     Me.ToolStripBox.Items.Add(FilterBox.GetItemText(item))
    3. Next item
    That said, if you have the FilterBox bound to a DataTable then, depending on the circumstances, it may be appropriate to simply bind the ToolStripBox to the same Datatable, e.g.
    vb.net Code:
    1. Dim bs As New BindingSource
    2.  
    3. bs.DataSource = FilterBox.DataSource
    4.  
    5. With Me.ToolStripBox.ComboBox
    6.     .DisplayMember = FilterBox.DisplayMember
    7.     .ValueMember = FilterBox.ValueMember
    8.     .DataSource = bs
    9. End With
    By creating a different BindingSource you enable the two controls to be bound to the data from the same DataTable without having to have the same record selected at the same time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    73

    Re: [2005] Simple Combobox problem [RESOLVED]

    Thanx jmcilhinney that workt grate

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