I need select from list containing product code and name but show only code
in combo textbox.
Tried code below but dropdown list shows only code.
How to display code AND name in selection list ?
Andrus.
using System.Collecti ons.Generic;
using System.Windows. Forms;
class testForm : Form
{
testForm()
{
ComboBox cm = new ComboBox() { DisplayMember = "DisplayMember" ,
ValueMember = "Code" };
List<Productpro dList = new List<Product>() ;
prodList.Add(ne w Product() { Code = "001", Name = "Wine", Cb =
cm });
prodList.Add(ne w Product() { Code = "002", Name = "Beer", Cb =
cm });
cm.DataSource = prodList;
cm.DataBindings .Add("SelectedV alue", prodList, "Code");
Controls.Add(cm );
}
class Product
{
public ComboBox Cb;
public string Code { get; set; }
public string Name { get; set; }
public string DisplayMember
{
get
{
if (Cb.DroppedDown )
return Code + " " + Name;
else
return Code;
}
}
}
static void Main()
{
Application.Run (new testForm());
}
}