Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello

I need to fill combo boxes on my form at form_load - I am not sure how to do it - I know it involves a For each loop - datase table something- combobox.add.item(dataset(dataRow) I have six tables only need to use five to fill the combos. they are make(car) interiorColor exteriorColor year soldstatus. these are all derived(Children?) of the Vehicles dataSet... excuse me for my lack of knowing which these are.

 

Any help would be appreciated

 

R

Posted

The For Each method:

 

       Dim ds As DataSet
       Dim dr As DataRow

       For Each dr In ds.Tables("TableName").Rows
           'This For Each loop will run through the tables
           'collection with dr acting as each datarow (record)
           'in the table specified.

           'Choose which item you're goin to add to which combobox
           ComboBox1.Items.Add(dr.Item("ColumnName").ToString)

           'This loop will loop through every datarow in your 
           'datatable, allowing you to add each value of a particular
           'column to your combobox.
       Next

 

Datasourced:

 

ComboBox1.DataSource = ds.Tables("TableName")
       ComboBox1.DisplayMember = ds.Tables("TableName").Columns("ColumnName").ToString

 

The second is much cleaner and faster and has some advantages when dealing with things like a listbox which can change records depending on which item you select.

 

The first has the advantage of you being able to play with your data. You can choose to concatonate two datacolumns (LastName, FirstName; Car, CarYear) and to sort them via the combo/listbox's sorted property (you can do the same in a datasource using the DataView.sort method). You can also add further items and change old ones at a later date.

 

But then you have to do searches to find out which record text is from, and that's also more complex.

Posted

That's fantastic!! Thank You!

Do I need some sort of counter? maxCount +=1 ????

 

 

Rob

 

The For Each method:

 

       Dim ds As DataSet
       Dim dr As DataRow

       For Each dr In ds.Tables("TableName").Rows
           'This For Each loop will run through the tables
           'collection with dr acting as each datarow (record)
           'in the table specified.

           'Choose which item you're goin to add to which combobox
           ComboBox1.Items.Add(dr.Item("ColumnName").ToString)

           'This loop will loop through every datarow in your 
           'datatable, allowing you to add each value of a particular
           'column to your combobox.
       Next

 

Datasourced:

 

ComboBox1.DataSource = ds.Tables("TableName")
       ComboBox1.DisplayMember = ds.Tables("TableName").Columns("ColumnName").ToString

 

The second is much cleaner and faster and has some advantages when dealing with things like a listbox which can change records depending on which item you select.

 

The first has the advantage of you being able to play with your data. You can choose to concatonate two datacolumns (LastName, FirstName; Car, CarYear) and to sort them via the combo/listbox's sorted property (you can do the same in a datasource using the DataView.sort method). You can also add further items and change old ones at a later date.

 

But then you have to do searches to find out which record text is from, and that's also more complex.

Posted
That's fantastic!! Thank You!

Do I need some sort of counter? maxCount +=1 ????

 

 

Rob

 

None needed, unless you're keeping track for some reason

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...