Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combobox valuemember
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00778451
Message ID:
00778559
Vues:
16
That’s great.
Anytime we had to concatenate fields around here we would use .Add and then reference the original datatable based on the selected index in order to get the PK.
I hated doing that.

Thanks a lot,

Chris


>Hi Chris,
>
>You can just add any object to the combobox you want. This object can
>contain any data you want. The combobox itself uses the ".ToString()"
>method to display the text. You can create a class that contains the value you want to associate with the text. Here is how to do this:
>
>
>class MyComboBoxItem
>{
>  public MyComboBoxItem(string Text)
>  {
>    text = Text;
>    itemData = 0;
>  }
>
>  public MyComboBoxItem(string Text, int ItemData)
>  {
>    text = Text;
>    itemData = ItemData;
>  }
>
>  public int ItemData
>  {
>    get
>    {
>      return itemData;
>    }
>    set
>    {
>      itemData = value;
>    }
>  }
>
>  public override string ToString()
>  {
>    return text;
>  }
>
>  protected string text;
>  protected int itemData;
>}
>
>
>To use this wih a ComboBox just do the following:
>
>comboBox1.Items.Add(new MyComboBoxItem("My text", 12));
>
>
>To access the ItemData:
>
>  MyComboBoxItem mci = (MyComboBoxItem)comboBox1.SelectedItem;
>  MessageBox.Show(mci.ItemData.ToString());
>
Chris
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform