Articles in this section
Category / Section

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

1 min read

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied