O'Reilly logo

Windows Forms Programming in C# by Chris Sells

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required