Update listbox item c#

To elaborate a little, because I know my answer might be a little cryptic:

Suppose the class you are displaying in the listbox looks like this:

public class foo
{
public string name;
public int age;
public foo[string aName, int anAge]
{
name= aName;
age = anAge;
}
public override string ToString[]
{
return name;
}
}
And you might be storing it in an array like so: private foo[] thelist;
private void Form1_Load[object sender, System.EventArgs e]
{
thelist = new foo[20];
for [int i = 0; i < thelist.Length; i++]
{
thelist[i] = new foo["foo " + i, i];
}
listBox1.DataSource = thelist;
}Alternatively, if you don't know how many you're going to be storing, you can just use an ArrayList: private ArrayList thelist;
private void Form1_Load[object sender, System.EventArgs e]
{
thelist = new ArrayList[];
for [int i = 0; i

Chủ Đề