Maybe I am missing the point here, since I never used the Binding features before. But, I think you can just override the ToString() method in your class like this:
Code:
public class testObject
{
public string name;
public string title;
public string address;
public override string ToString(){
return name;
}
}
and if you next just set the DataSource property to the array it works as far as I know:
Code:
comboBox1.DataSource = arr;
Next you can just access your address like this:
Code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
testObject o = (testObject)comboBox1.SelectedItem;
MessageBox.Show(o.address);
}
But please either way don't use public variables. It's a very very very bad practice.
The following is a lot cleaner:
Code:
public class TestObject
{
string strName;
string strTitle;
string strAddress;
public TestObject()
{
}
public TestObject(string name, string title, string address) : this()
{
strName = name;
strTitle = title;
strAddress = address;
}
public string Name
{
get { return strName; }
set { strName = value; }
}
public string Title
{
get { return strTitle; }
set { strTitle = value; }
}
public string Address
{
get { return strAddress; }
set { strAddress = value; }
}
public override string ToString()
{
return strName;
}
}