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

how to create a dropdownlist and find index by value?

P: n/a
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
Dec 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Dec 25 '07 #2

P: n/a
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.
Dec 26 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.