1 / 6

Exploring C# Data Binding with BindingList Class in Windows Forms

This course provides an in-depth look at C# data binding, specifically using the BindingList class. Learn the fundamentals of creating a BindingList that supports IList interfaces while handling list change events and enabling sorting. Through practical examples, students will develop a simple Windows Form application that includes a ListView, ComboBox, and buttons to dynamically add items to the list. Gain skills in using data binding in C# to enhance user interface interactivity and responsiveness. Ideal for those looking to expand their programming expertise in C# and Windows Forms.

albin
Télécharger la présentation

Exploring C# Data Binding with BindingList Class in Windows Forms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming in C#Data Binding to Controls CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis

  2. The BindList class • The BindingList class provides a generic wrapper around a collection supporting the IList interface. • It provides list changed events and many other properties (including sorting). • The easiest way to create one is by passing in an existing collection: IList<int> numberList = newList<int>(20); BindingList<int> bindingNumbers = newBindingList<int>(numberList);

  3. Example • A simple Windows Form with a listView a ComboBox and a button to add more items.

  4. Example publicpartialclassForm1 : Form { privateBindingList<int> bindingNumbers; privateIList<int> numberList = newList<int>(20); privateintnextNumber = 10; publicForm1() { InitializeComponent(); for(inti = 0; i < nextNumber; i++) numberList.Add(i); bindingNumbers= newBindingList<int>(numberList); listBox1.DataSource = bindingNumbers; comboBox1.DataSource = bindingNumbers; }  privatevoidaddButton_Click(object sender, EventArgse) { bindingNumbers.Add(nextNumber++); } }

  5. Formatted Text • Note that the controls displayed the integers. • Each control will use a Formatter to convert the object to a string representation. • This is typically the default ToString() method of the object. • Works for any type:

  6. Example 2 publicpartialclassForm1 : Form     { privateBindingList<object> bindingObjects; privateIList<object> objectList = newList<object>(20); public Form1()         { InitializeComponent(); for (inti = 1; i < 10; i++) objectList.Add(newDateTime(2008,5,i)); for (inti = 10; i < 14; i++) objectList.Add(i); objectList.Add("Hello World"); objectList.Add(numberList); bindingObjects = newBindingList<object>(objectList);             listBox1.DataSource = bindingObjects;             comboBox1.DataSource = bindingObjects;

More Related