Good Morning,
I'm want to display names in a combobox. The problem I have is with
duplicate names, I want to update or retrieve information on a
certian person but if there are dups I get the wrong one. How do I
load the names into the combobox and an identity field to tel them
apart.
Thanks..
Jim
Set up a class containing the data you are interested in and then add
instances of of the class to the combo - if you override the 'ToString'
function you can show the name perhaps plus an identifier in the combo.
Something like:
using System;
namespace JFilerCtl
{
/// <summary>
/// Maintain link between Path and TV FullPath
/// </summary>
public class CComboData
{
public string m_strName = "";
public int m_intID = "";
public CComboData()
{
//
// TODO: Add constructor logic here
//
}
// Override ToString method so that m_strPath is default
public override string ToString()
{
return this.m_strName + "- " + this.m_intID.ToString();
}
}
}
You then set up an instance of the class:
CComboData ccd = new CComboData();
ccd.m_strName= John Smith'
ccd.m_intID = 1234;
Then add to the Combo:
MyCombo.Iems.Add(ccd);
The Combo will show:
John Smith - 1234
To retrieve your record you use:
CComboData ccdTemp = (CComboData)MyCombo.SelectedItem;
You can then use ccdTemp.m_intID, and ccdTemp.m_strName to retieve your
data.
Hope this is clear, if it works for you you will want to clean the
class up possibly. I have copied and pasted this so check it carefully,
I've also just had a PC blow up so my spell checker isn't working on
this so apologies for typos