473,666 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4826
On Dec 25, 2:04*pm, "GS" <gsmsnews.micro soft.co...@msne ws.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 codeTableBindin gSource and codeTableSqlada ptor for the above
table
my first try was with listbox
then I populate the codeTableListbo x with

this.codeTableA dapter.Fill(thi s.myTmpDataSet. codeTable);
codeTableListbo x.DisplayMember = "displayNam e";
codeTableListbo x.ValueMember = "codeTable" ;
codeTableListbo x.DataSource = codeTableBindin gSource;
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()) {
codeTableListbo x.setSelected( i, true);
codeTableListbo x.tag = objDataRowView["helpText"].ToString()
break;
}
}

not elegant but works. would have been nice if Microsoft have implemented
listbox.findVal ue("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********@gma il.comwrote in message
news:7e******** *************** ***********@e10 g2000prf.google groups.com...
On Dec 25, 2:04 pm, "GS" <gsmsnews.micro soft.co...@msne ws.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
2268
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) private int GetMatchingIndexOfDropDown(ref DropDownList d, string MatchValue) { return }
6
7004
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 changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected value and not 0. It seems that it is getting the selected value from the viewstate
1
1706
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 is a dropdownlist and the other is a button which runs the command selectcode for this:
2
11309
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 database. for example: if the ddl_value is 2 from the database i want the second list item to be selected by default.
6
16607
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"); dd.Items.Add("1991"); dd.Items.Add("1992");
2
16084
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 in my asp tag as shown here: <asp:DropDownList id="ddlTo" runat="server"
1
4652
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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3493
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- 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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
1
260
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 get error of 'object required'. when i break and quick-watch the value of document.getElementById("cboLocation") , it shows 'null'. btw, there is a value in dropdownlist. what should i change?? actually, when i do quickwatch of document then...
0
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8362
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8644
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.