CSE459_CSharp_Extra_DataBinding

CSE459_CSharp_Extra_DataBinding - listBox1.DataSource =...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming in C# Data Binding to Controls CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The BindList class l The BindingList class provides a generic wrapper around a collection supporting the IList interface. l It provides list changed events and many other properties (including sorting). l The easiest way to create one is by passing in an existing collection: IList < int > numberList = new List < int >(20); BindingList < int > bindingNumbers = new BindingList < int >(numberList);
Background image of page 2
Example l A simple Windows Form with a listView a ComboBox and a button to add more items.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example public partial class Form1 : Form { private BindingList < int > bindingNumbers; private IList < int > numberList = new List < int >(20); private int nextNumber = 10; public Form1() { InitializeComponent(); for ( int i = 0; i < nextNumber; i++) numberList.Add(i); bindingNumbers = new BindingList < int >(numberList);
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: listBox1.DataSource = bindingNumbers; comboBox1.DataSource = bindingNumbers; } private void addButton_Click( object sender, EventArgs e) { bindingNumbers.Add(nextNumber++); } } Formatted Text l Note that the controls displayed the integers. l Each control will use a Formatter to convert the object to a string representation. l This is typically the default ToString() method of the object. l Works for any type: Example 2 public partial class Form1 : Form { private BindingList < object > bindingObjects; private IList < object > objectList = new List < object >(20); public Form1() { InitializeComponent(); for ( int i = 1; i < 10; i++) objectList.Add( new DateTime (2008,5,i)); for ( int i = 10; i < 14; i++) objectList.Add(i); objectList.Add( "Hello World" ); objectList.Add(numberList);...
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 6

CSE459_CSharp_Extra_DataBinding - listBox1.DataSource =...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online