By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,774 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,774 IT Pros & Developers. It's quick & easy.

Combobox begginger question

P: n/a
I have the code below to fill a combobox. I would appreciate any
comments on a better way to do this fill.

My may problem is how do I set the selected combo box display value
based on the "Id" column and a value of "paytype". Also once the user
selects a combobox item from the dropdown how do I then retrieve the
"paytype" value.

void Fill_LookupType()
int nItem;
nItem = 0;

string select = "SELECT description, lookuptypevalue ";
select += "FROM lookuptypes ";
select += "WHERE active = 1 ";
select += "ORDER BY description ASC ";
dbConnect Connection = new dbConnect();
OdbcConnection conn = new OdbcConnection( @Connection.Connect());
OdbcCommand cmd = new OdbcCommand(select,conn);
OdbcDataReader aReader = cmd.ExecuteReader();

DataTable list = new DataTable();
list.Columns.Add(new DataColumn("Display", typeof(string)));
list.Columns.Add(new DataColumn("Id", typeof(string)));

list.Rows[nItem][0] = aReader.GetString(0);
list.Rows[nItem++][1] = aReader.GetString(1);


this.cb_LookupType.DataSource = list;
this.cb_LookupType.DisplayMember = "Display";
this.cb_LookupType.ValueMember = "Id";

Jan 24 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.