roger rickert

roger rickert

  • NA
  • 21
  • 1.1k

C# winforms databinding question

Jan 19 2021 3:40 PM
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)