Hi,
Please make sure the obj is in the Collection, it should be the exact object that exists in the collection that is not a copy. Something like this works well.
Code Snippet
partial class Form21 : Form
public Form21()
private void Form21_Load(object sender, EventArgs e)
new OBJ(1));
new OBJ(2));
new OBJ(3));
new OBJ(4));
//bothwaysto populate the ListBox will workwell //1. Data binding //this.listBox1.DataSource = objs; //2.Add items manually
foreach (OBJ o in objs)
this.listBox1.Items.Add(o);
List<OBJ> objs= new List<OBJ>();
private void button1_Click(object sender, EventArgs e)
this.listBox1.SelectedItem = objs[2];
class OBJ
private int id;
public OBJ(int id)
this.id = id;
public int Id
get { return id; }
set { id = value; }
public override string ToString()
return id.ToString();
Could you paste your code here and tell me your reqirement .
|