)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind the data source in code behind in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: May 10, 2016 |
Last Revised Date: February 12, 2020
Tags: binding

Bind the data source

In order to bind the data source at runtime, the DataSource property can be used. In this below article, the datasource of the GridGroupingControl can be changed by clicking the Change Datasource button.

C#

Random rand = new Random();
int r = rand.Next(100);
//Generating datasourcce by using IBindingList.
dataSource = new DataCollection();
//Generating DataSource by using Random values.
for (int i = 0; i < 30; i++)
{
    dataSource.Add(new Data(r.ToString(), "Category" + r.ToString(), "Desc" + r.ToString()));
    r = rand.Next(100);
}
 //Assigning datasource for grid.
 this.gridGroupingControl1.DataSource = dataSource;
 
//used for Adding record to data source
private void btnChangeDataSource_Click(object sender, EventArgs e)
{
  DataSet ds = new DataSet();
  ReadXml(ds, @"Expand.xml");
  this.gridGroupingControl1.DataSource = ds.Tables[0];
 
}

VB

Dim rand As New Random()
Dim r As Integer = rand.Next(100)
'Generating datasourcce by using IBindingList.
dataSource = New DataCollection()
'Generating DataSource by using Random values.
For i As Integer = 0 To 29
   dataSource.Add(New Data(r.ToString(), "Category" & r.ToString(), "Desc" & r.ToString()))
   r = rand.Next(100)
Next i
'Assigning datasource for grid.
Me.gridGroupingControl1.DataSource = dataSource
 
Private Sub btnChangeDataSource_Click (ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
  Dim ds As New DataSet()
  ReadXml(ds, "Expand.xml")
  Me.gridGroupingControl1.DataSource = ds.Tables(0)
End Sub

 

Show bind the data source at runtime

Samples:

C#: Binding DataSource_CS

VB: Binding DataSource_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon