Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populating a combobox with a list objetct
Message
De
05/08/2010 14:43:12
 
 
À
05/08/2010 13:56:09
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01475380
Message ID:
01475399
Vues:
32
>i have a combobox that's populated using a foreach loop through a list object. There are three items from the database that get added to the list: id, paycode, description. The only way I know how to do it is by creating a string. But what I need is to separate the id into it's own column, so we can use it to do a lookup through a stored procedure. Can anyone tell me how this is done?
>
>Thanks!

Can you use an object for the ListBox binding ? eg:
   public class Thing
    {
        public int Id { get; set; }
        public int PayCode { get; set; }
        public string Description { get; set; }
    }
then:
List<Thing>  things = new List<Thing>();
            things.Add(new Thing{Id=1,PayCode=2,Description="One Thing"});
            things.Add(new Thing { Id = 2, PayCode = 3, Description = "Another Thing" });
            listBox1.DataSource = things;
            listBox1.DisplayMember = "Description";
When you need to see which item is selected:
Thing  thing = (Thing) listBox1.SelectedItem;
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform