Tuesday 14 February 2017

What is Data Bound Control?

Data-bound controls are WinForms controls those can easily bind with data components.
Data-bound controls have properties, which you can set as a data component and they are ready to present your data in WinForms. Data Source and Display Memeber are two important properties.

Data Source property of these controls plays a major role. You can set different kind of data components as datasource property of a control. For example, you can set a defaultViewManager or a DataView as this property.
DataSet ds = new DataSet();  
dataGrid1.DataSource = ds.DefaultViewManager;
DisplayMember property can be set to a database table field name if you want to bind a particular field to the control.
DataSet ds = new DataSet();
// Attach dataset's DefaultView to the datagrid control
DataView dv = ds.Tables["Employees"].DefaultView;
listBox1.DataSource = dv;
listBox1.DisplayMember = "FirstName";

No comments:
Write comments