|
-
May 1st, 2008, 10:54 AM
#1
ComboBox
Trying to load a combobox dynamically with the following piece of code.
count gives exact number of rows !!, but the combobox does not show anything..!!.
Any help is greatly appreciated.
Code:
public void loadComboBox(OdbcConnection con)
{
con = getConnection();
con.Open();
string str = "select distinct mgrCode from MgrDetail";
OdbcCommand nonqueryCommand = con.CreateCommand();
nonqueryCommand.CommandText = str;
nonqueryCommand.CommandType = CommandType.Text;
OdbcDataReader thisReader = nonqueryCommand.ExecuteReader();
DataSet ds = new DataSet();
DataTable dTable = new DataTable("TableA");
dTable.Load(thisReader);
ds.Tables.Add(dTable);
this.ComboBox1.DataSource = ds.Tables[0];
int count = this.ComboBox1.Items.Count; //count gives exact number of rows !!
con.Close();
}
Yes, Possible!!
-
May 1st, 2008, 11:05 AM
#2
Re: ComboBox
You need to set DisplayMember and ValueMember for ComboBox. Like:
Code:
ComboBox1.DisplayMember = FieldNameinDataTable;
The difficulty is that you have no idea how difficult it is.
.Net 3.5/VS 2008
-
May 1st, 2008, 12:08 PM
#3
Re: ComboBox
That worked..
Thanks a lot.
Yes, Possible!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|