I have sql table codeTable with the following columns
value, displayname, helptext
I set up a codeTableBindingSource and codeTableSqladaptor for the above
table
my first try was with listbox
then I populate the codeTableListbox with
this.codeTableAdapter.Fill(this.myTmpDataSet.codeT able);
codeTableListbox.DisplayMember = "displayName";
codeTableListbox.ValueMember = "codeTable";
codeTableListbox.DataSource = codeTableBindingSource;
that does display the displayname as desired.
my problem #1 is finding the index for a given valuex so I can set the
proper value to be selected
which I finally found an answer after hours on Google
int i=-1;
foreach (DataRowView objDataRowView in listBox1.Items)
{
i++;
if (valuex == objDataRowView["id"].ToString()) {
codeTableListbox.setSelected( i, true);
codeTableListbox.tag = objDataRowView["helpText"].ToString()
break;
}
}
not elegant but works. would have been nice if Microsoft have implemented
listbox.findValue("somestring")
have yet to try out the suggestion for setting the tag for help text as I
don't understand yet how to use tag for help.
<De********@gmail.comwrote in message
news:7e**********************************@e10g2000 prf.googlegroups.com...
On Dec 25, 2:04 pm, "GS" <gsmsnews.microsoft.co...@msnews.Nomail.com>
wrote:
I want to create a dropdownlistbox in my windows form with name value
pair.
but I need to initialize its initial selected value to a value from
database
for the record.
I was going to just use the listbox and find in the view source the record
number as index. but it did not work consistently. it worked for the first
listbox but not the 2nd listbox.
Furthermore, I really want to list not only the description for the value
but also a helptext column.
I did some Google, so far I found info mostly on webui as well as being to
able to list more than one column in a modified combobox but not find by
value
Your time and advice would be much appreciated. thank you
You may use Tag attribute.
If possible, paste your code here and it will be more helpful.