how to create a dropdownlist and find index by value?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GS

    how to create a dropdownlist and find index by value?

    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

    #2
    Re: how to create a dropdownlist and find index by value?

    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.

    Comment

    • forum.microsoft.com

      #3
      Re: how to create a dropdownlist and find index by value?

      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.



      <Dengbo.Cui@gma il.comwrote in message
      news:7e789c7f-90f3-4a0a-b189-59a7baa07616@e1 0g2000prf.googl egroups.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.


      Comment

      Working...