Groups | Blog | Home
all groups > dotnet academic > october 2005 >

dotnet academic : combobox question


shawn
10/31/2005 1:23:04 PM
I am loading a combo box with employee names.

the table looks like this:
EmployeeID,employeeName
1 me
2 You

etc

I have executed a SQL select and returned both fields to a SQLReader object
(SQLReader is a OleDb.OleDbDataReader Object)

my problem is i need to set the indexs of my combo box entries equal to the
values returned in the EmployeeID field. Im not sure how to do that.

Thanks for any help
pvdg42
11/1/2005 8:22:08 AM

[quoted text, click to view]

The ComboBox index is zero-based. So, if you don't have (or create) a row
with EmployeeID = 0, you won't get there. If you do that, then you'll need
to sort the rows coming into your SQLReader on EmployeeID.
If there are any gaps in the sequence of values in the EmployeeID field, the
above techniques will not work.
Why do you need the ComboBox index value to equal EmployeeID?

Jim Underwood
11/2/2005 5:06:38 PM
You can bind it to the dataset. This does not actually affect the indexes
in the combo box, they will simply start at 0 and increment for each value
added. This will, however, store the employeeID in the combo box, which is
probably what you need to do.

In my case I use a datatable, not sure if SQLReader works but I think it
should.

Basically you set the combobox to display one field but store another as the
value.

if you are using VB.Net, you will do it soemthign like this...

ComboBox1.DataSource = datatable1
ComboBox1.DisplayMember = "employeeName"
ComboBox1.ValueMember = "EmployeeID"

Then
ComboBox1.SelectedValue
will give you the EmployeeID.


[quoted text, click to view]

AddThis Social Bookmark Button