ListBox.DisplayName problem
-
hi all i have a ListBox and i want it to receive a Pair object and show me the Second value of the Pair in ListBox but it shows me the ToString() method of Pair "System.Web.UI.Pair" witch means the property name is incorrect what should i do? my code is :
ArrayList list = new ArrayList(); list.Add(new Pair("A", "B")); lstBox.DataSource = list; lstBox.DisplayMember = "Second";
-
hi all i have a ListBox and i want it to receive a Pair object and show me the Second value of the Pair in ListBox but it shows me the ToString() method of Pair "System.Web.UI.Pair" witch means the property name is incorrect what should i do? my code is :
ArrayList list = new ArrayList(); list.Add(new Pair("A", "B")); lstBox.DataSource = list; lstBox.DisplayMember = "Second";
Unfortunately Pair contains only public fields named First and Seconds, but DisplayMember specify a name of the PROPERTY to display. So you could make it work like this
{
//form classprivate void Form1_Load(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
MyPair f = new MyPair("A", "B");
list.Add(f);
listBox1.DataSource = list;
listBox1.DisplayMember = "second";
}
}class MyPair { public object First { get; set; } public object Second { get; set; } public MyPair(object a, object b) { this.First = a; this.Second = b; } }
-
Unfortunately Pair contains only public fields named First and Seconds, but DisplayMember specify a name of the PROPERTY to display. So you could make it work like this
{
//form classprivate void Form1_Load(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
MyPair f = new MyPair("A", "B");
list.Add(f);
listBox1.DataSource = list;
listBox1.DisplayMember = "second";
}
}class MyPair { public object First { get; set; } public object Second { get; set; } public MyPair(object a, object b) { this.First = a; this.Second = b; } }
thank you for your attention i really love this site with its responsible people