1
Answer

C# winforms databinding question

roger rickert

roger rickert

4y
599
1
Hello,   I have a databinding question.     I have a List of objects that contain multiple fields.   Is there a way to bind a control (ex. label) to a specific field in one of the objects?      here's some pseudo code to help illustrate:
 
Class:
 
public class StoreFields
{
    public string apple;
    public string orange;
    public string grape;
}
 
I create a list of those objects:
 
public static List Store = new List(3)
{
    new StoreFields(),
    new StoreFields(),
    new StoreFields()
}
 
I then have some labels that I'd like to databind with fields from the objects in that list.     
for example:
 
databind Label1 to Store[1].Apple
 
I tried:
 
Lable1.DataBindings.Add("Text", Store[1].Apple, "Text"); 
 
The following exeption was thrown:
 
{"Cannot bind to the property or column Value on the DataSource.\r\nParameter name: dataMember"} 
 
 is something like this possible?
Answers (1)