Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

how to create a dropdownlist and find index by value?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GS - 25 Dec 2007 06:04 GMT
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
Dengbo.Cui@gmail.com - 25 Dec 2007 06:44 GMT
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
[quoted text clipped - 12 lines]
>
> 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.
forum.microsoft.com - 26 Dec 2007 07:11 GMT
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.

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.
[quoted text clipped - 14 lines]
>
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.