how to create a dropdownlist and find index by value?

  • Thread starter Thread starter GS
  • Start date Start date
G

GS

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
 
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.
 
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.codeTable);
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.



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top