$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
ListView WinForms Control
Create elegant user interfaces, display data, group, filter, sort, and customize data items
Home > WinForms UI Controls > User Manual > ListView DataBinding in C#

ListView Control Data Binding in C#.NET

Kettic ListView .NET control is capable of binding to data source to display those data. There are three properties available for the users to bind ListView to data, the DataSource, ShowMember, and ValueMember. The DataSource property is used to specify the data source that the ListView will be bound to, the ShowMember displays the specific data in a ListView, and the ValueMember returns the value of a ListView from the specific data.

How to Configure DataBinding Properties

The DataSource property can be configured either in the Properties windows or in the Smart Tag menu of Kettic ListView control. The following steps show how to the DataSource and ValueMember and ValueMember properties.
  • Choose the DataSource property and click the drop-down arrow
  • All existing data sources will be shown on the form and click the Add Project Data Source link and follow the instructions in the Data Source Configuration Wizard
  • Add a data source to your project. The available data source includes databases, web services, or business objects.
  • After setting the DataSource, choose a DisplayMember and ValueMember.
  • The DisplayMember is able to specify the data shown in KetticListView’s items.
  • The ValueMember is able to specify the data returned by the Value property in Kettic ListView's items.

How to Customize Columns in ListView in C#.NET

After we bind the Kettic ListView control to a collection of business objects and choose the ViewType to be DetailsView, the columns will display the values of all the properties of the business objects. We can customize the column size, viability, and other properties by handling the CreateColumn event. The C# code below shows how to create columns in C#.NET.

void ketticListView1_CreateColumn(object sender, Kettic.WinForms.UI.ListViewCreateColumnEventArgs e)
{
if (e.Column.FieldName == "StudentID" || e.Column.FieldName == "ParentID")
{
e.Column.Visible = false;
}

if (e.Column.FieldName == "StudentName")
{
e.Column.HeaderText = "Class";
}

if (e.Column.FieldName == "Home Adrress")
{
e.Column.HeaderText = "Contact";
}
}

How to Bind ListView to Data in C#.NET

The guide below shows how to bind a ListView component to a list of business objects in C#.NET project. We will create a business object first and the custom object will implement the ChangedINotifyProperty interface. After that, we can create a collection of our business objects by using the C# code below.
To bind the Kettic ListView control to this collection, we can simply configure the properties, DataSource, DisplayMember and ValueMember by using the C# code below.

this.ketticListView1.DataSource = dataSource;
this.ketticListView1.DisplayMember = "StudentName";
this.ketticListView1.ValueMember = "StudentID";
After setting these properties, we will get the Kettic ListView populated with items that display the value Name property and the ID property of the business object returned as value. We can see them via opening an item for editing.
To extend the functionality of the case, we can handle the ItemDataBound event, which will be fired after assigning the ListViewDataItem an object from the data bound. We can access the data bound object properties in the event handler and assign an image to the item by using the C# code below.

void ketticListView1_ItemDataBound(object sender, Kettic.WinForms.UI.ListViewItemEventArgs e)
{
{
if (ketticListView1.ViewType == Kettic.WinForms.UI.ListViewType.ListView)
{
e.Item.Image = ((Person)e.Item.DataBoundItem).Picture;
}
}
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls