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?