Custom Data Sources

Although the data set is a popular data source, it's by no means the only one. Any custom type can be a data source.

Custom Item Data Sources

The requirements of an item data source are only that it expose one or more public properties:

// Expose two properties for binding
class NameAndNumber {
  public string Name {
    get { return name; }
    set { name = value; }
  }

  public int Number {
    get { return number; }
    set { number = value; }
  }

  string name = "Chris";
  int number = 452;
}

NameAndNumber source = new NameAndNumber();

void CustomItemDataSourceForm_Load(object sender, EventArgs e) {
  // Bind to public properties
						textBox1.DataBindings.Add("Text", source, "Name");
						textBox2.DataBindings.Add("Text", source, "Number");
}

In this case, ...

Get Windows Forms Programming in C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.