Results 1 to 3 of 3

Thread: [RESOLVED] Array to combobox

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Resolved [RESOLVED] Array to combobox

    hey all...

    a quick question regarding binding an array to comboboxes.

    i have mutilple comboboxes which will contain the hours and minutes

    so i've create 2 arrays, one containing the hours and one containing the minutes

    Code:
    Dim l_hours As String() = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"}

    so i want to assign the hours to several comboboxes. I do this by:
    Code:
    cbo1.DataSource = l_hours
    cbo1.SelectedIndex = -1
    
    cbo2.DataSource = l_hours
    cbo2.SelectedIndex = -1
    however whatever value i select in cbo1 it is set in cbo2 aswell.
    eg: i select 10 from the dropdown in cbo1, when this is selected 10 becomes the selected value in cbo2.

    can someone explain this to me... there something im not doing right here
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: Array to combobox

    Code:
         Dim int As Integer
            Dim aint() As Integer
            aint = New Integer() {0, 15, 30, 45}
            'lunchtijd(max 1 uur)
            Dim aintlunch() As Integer
            aintlunch = New Integer() {0, 15, 30, 45, 1}
    
            For int = 0 To 23
                cmbaanuur.Items.Add(int)
                cmbvertrekuur.Items.Add(int)
                cmbwachtuurb.Items.Add(int)
                cmbwachtuure.Items.Add(int)
            Next
    
            For int = 0 To 3
                cmbaanmin.Items.Add(aint(int))
                cmbvertrekmin.Items.Add(aint(int))
                cmbwachtminb.Items.Add(aint(int))
                cmbwachtmine.Items.Add(aint(int))
            Next
    
            For int = 0 To 4
                cmblunchtijd.Items.Add(aintlunch(int))
            Next
    Im doing the same thing to , but i use a for loop , maybee you dont want to use it but mine does work.

    I think you setting a DataSource to 2 comboboxes could be the problem , maybe you'll have to make a second array for the second box and use that as the datasource.


    PS: check if you havent accidently placed CMB1 with CMB2 when you try to get the data from something

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Array to combobox

    This solved my problem
    Code:
            cbo1.BindingContext = New BindingContext()
            cbo1.DataSource = l_hours
    
            cbo2.BindingContext = New BindingContext()
            cbo2.DataSource = l_hours
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework 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