473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 2647
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon | last post by:
Hi all, I am trying to dynamically fill an array with any unique values from a field (objRS.Fields(5)) in my database with the following code below. However it errors with "The array is fixed...
2
by: RelaxoRy | last post by:
I have 3 texfield boxes 1. firstname 2. lastname 3. username When a person enters in their firstname and lastname, I want the username field to fill with firstnameLastinitial. Eg. ...
2
by: John Scott | last post by:
Hi there, I have a PDF that has editable form fileds. I want to be able dynamically fill in those form fields based on values I provide to the PDF. Right now, I can create an instance of the...
1
by: Zameer Syed | last post by:
I have a webform in which users enter their information and there is a button at the end of form,which when clicked should open a word document with fields filled in dynamically with the...
3
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not...
4
by: blg002 | last post by:
All I am trying to do is dynamically fill the "Your Price" field with a number that is the product of the value of "acres" "regularity" and 10. The annoying part is I had it working yesterday and...
5
by: buntyindia | last post by:
Hi, I have three Listbox on my jsp page. I want to do following: ByDefault first list will be filled by database, When User select something from 1st list box second will fill accordingly ...
0
by: sravan_reddy001 | last post by:
I am developing a e-news website.. i bought space from websuvidha.org.. they are also providing some emails... http://mail.asianmedianetworkinc.com/ http://216.157.131.123/index.php the...
0
by: malsh1358 | last post by:
I created Jaxb java classes and now I want to fill them dynamically , but I dont know how I can dynamically fill JAXB java objects (I can do it in fix way) ,I must say that their data are in xml file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.