Combobox Question..!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 :-)
 
Jeff,

Thanks... I'm using VB.Net. Sorry I didn't clerify this. Can you still
assist with this?

Thanks Again...!

Jim
 
Jeff,

Thanks... I'm using VB.Net. Sorry I didn't clerify this. Can you
still assist with this?

Thanks Again...!

Jim

Hi Jim

I don't use VB.NET but my understanding is that it's very similar, you
would need to take out the curly brackets '{' and '}' and remove the
semi-colons at line ends.

Best start would be to add the class in your project which will give
you an outline and then translate step by step.
 
Hello,

Let's clarify the scenario. You would like to display names of people in a
combobox and when you select a name you would like to know which was
selected.

The first thing you need to do is figure out what the unique id is for the
person. In this case, you could use a unique id field for every person in
your database or possibly use a social security number (be careful for non
US citizen if using Social Security #)

When you load the combobox set the value member to the unique id. Then when
you select an item you can get the unique id for the person.

Tom

Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/smartclient/

This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top