472,146 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

dynamically fill a selectbox

I would like to fill a Selectbox dynamically.
I am taking all values from a db, and fill them into a selectbox.
I guess the best way was to use some kind of a dynamical array, where you
don't have to say how many
elements it will contain.
In Java there exists special containers to achieve that, but what about VB?
I thought about somethign like that:

select year from db

while dynamischesArray.AddNewValue(nextResult)

How to get this done as easy and good as possible?

Thanks,

Stefan
Nov 20 '05 #1
3 2601
For aWebForm, if you mean by selectbox a ListBox, then here is an example:

For ds a DataSet, states.xml an XML file containing a list of states with
Field1 containing the state abbreviation, you would do the following to
populate the list box DropDownStateList:

ds.Clear()
ds.ReadXml(Server.MapPath(".") & "\states.xml")
Me.DropDownStateList.DataSource = ds
Me.DropDownStateList.DataTextField = "Field1"
Me.DropDownStateList.DataBind()
For aWindowsForm, and a ComboBox, it would be something like

ds.Clear()
ds.ReadXml("..\states.xml")
Me.ComboBoxState.DataSource = ds.Tables(0)
Me.ComboBoxState.DisplayMember = "Field2" 'name
Me.ComboBoxState.ValueMember = "Field1" 'abreviation

"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
I would like to fill a Selectbox dynamically.
I am taking all values from a db, and fill them into a selectbox.
I guess the best way was to use some kind of a dynamical array, where you
don't have to say how many
elements it will contain.
In Java there exists special containers to achieve that, but what about VB? I thought about somethign like that:

select year from db

while dynamischesArray.AddNewValue(nextResult)

How to get this done as easy and good as possible?

Thanks,

Stefan


Nov 20 '05 #2
I found it by myself:

Dim yearArrayList As New ArrayList

While (MyDataReader.Read())

yearArrayList.Add(MyDataReader.Item("year"))
Nov 20 '05 #3
* "Stefan Richter" <sp**@spammenot.com> scripsit:
I found it by myself:

Dim yearArrayList As New ArrayList

While (MyDataReader.Read())

yearArrayList.Add(MyDataReader.Item("year"))


What's a selectbox? The questions remains unanswered ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Scott | last post: by
1 post views Thread by Zameer Syed | last post: by
reply views Thread by sravan_reddy001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.