473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to create a dropdownlist and find index by value?

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
2 4807
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Earl Teigrob | last post by:
I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item that matchs (or -1 if there is no match) ...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
1
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one...
2
by: huzz | last post by:
How do i make a dropdownlist selected value based on the value i retrive from the database. Basically i have an edit page and like to display the default value in a dropdown list from the...
6
by: Oscar | last post by:
I want to add items to a dropdownlist control within a Javascript eventhandler. This is what I code : var dd = document.getElementById("DropDownList1"); dd.Items.Add("1990");...
2
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: CreativeMind | last post by:
I updated my application from VS2003(.NET framework 1.1) to VS2008(.NET framework 3.5). My form uses a dropdownlist cboLocation. In 1.1 there is no error accessing that form. but when i use 3.5, i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.