Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding Items to Listbox
Message
De
01/07/2005 00:56:27
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01026697
Message ID:
01028030
Vues:
14
Since you're not databinding to a DataTable, using a ListView might be easier than using a ListBox. Your code would be something like this:
    ListViewItem item = new ListViewItem()
    item.Text = cEmpName 
    item.Tag  = iEmpID
Then, in the .SelectedIndexChanged event handler, you'd use the .SelectedItems property to get at the Tag for the selected item, which would be your ID.

~~Bonnie


>Hi
>
>Could anybody give me some 'best practice' guidelines when adding items to listboxes?
>
>I need to add a series of values to a listbox , say employee names and the employees id
>
>The Employee name would be the displaymember and the employee Id would be the valuemember.
>
>In the listbox I would like to display the name but behind the scenes store the id so that when the user clicks on an employee in the list box I can work out what the ID is for the selected employee.
>
>I'm not using a datatable or an array at the moment, but need to add a series of values from an external com component.
>
>so my code looks something like this ;
>
>EmployeesClass oEmps = new EmployeesClass();
>
>int lnRetValue = 0
>
>lnRetValue = oEmps.first()
>while(lnRetValue != -2)
>{
>    cEmpName = oEmps.GetEmpName()
>    iEmpID   = oEmps.GetEmpId()
>
>    * need to populate the list box items here...
>
>    lnRetValue = oEmps.next() - this will return -2 when we hit the last record.
>
>}
>
>
>Anybody got any pointers for me?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform