here is the solution
paste this in .cs file and ensure there is no other Main function in
project
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
namespace MyListControlSample
{
public class ListBoxSample3 : Form
{
private TextBox textBox1 = new TextBox();
private ComboBox cmb = new ComboBox();
[STAThread]
static void Main()
{
Application.Run(new ListBoxSample3());
}
public ListBoxSample3()
{
this.ClientSize = new Size(292, 181);
this.Text = "ListBox Sample3";
cmb.Location = new Point(24, 16);
cmb.Name = "cmb";
cmb.Size = new Size(232, 130);
textBox1.Location = new Point(24, 160);
textBox1.Name = "textBox1";
textBox1.Size = new Size(240, 24);
this.Controls.AddRange(new Control[] { cmb, textBox1 });
// Populates the combo box using DataSource.
// DisplayMember is used to display just the long name of
each state.
ArrayList USStates = new ArrayList();
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI"));
USStates.Add(new USState("Wyoming", "WY"));
cmb.SelectedIndexChanged += new
EventHandler(cmb_SelectedIndexChanged);
cmb.DataSource = USStates;
cmb.DisplayMember = "LongName";
cmb.ValueMember = "ShortName";
}
void cmb_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmb.SelectedIndex != -1)
textBox1.Text = cmb.SelectedValue.ToString();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// ListBoxSample3
//
this.ClientSize = new System.Drawing.Size(658, 347);
this.Name = "ComboSample3";
this.ResumeLayout(false);
}
}
public class USState
{
private string myShortName;
private string myLongName;
public USState(string strLongName, string strShortName)
{
this.myShortName = strShortName;
this.myLongName = strLongName;
}
public string ShortName
{
get
{
return myShortName;
}
}
public string LongName
{
get
{
return myLongName;
}
}
public override string ToString()
{
return this.ShortName + " - " + this.LongName;
}
}
}
I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com