)
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 set the number of rows and columns in a WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 19, 2019

Setting row and column count

You can change the Grid’s RowCount and ColCount properties by using the designer. Set these properties after calling InitializeComponent in the form’s constructor or anytime later in your code using the following code example.

Using direct properties

C#

// set RowCount for GridControl
gridControl1.RowCount = 20;
// set ColCount for GridControl
gridControl1.ColCount = 120;

VB

' set RowCount for GridControl
gridControl1.RowCount = 20
' set ColCount for GridControl
gridControl1.ColCount = 120

Using Events

The events QueryRowCount and QueryColCount are used to set the count for rows and columns.

C#

//Hook these events to set the RowCol count 
gridControl1.QueryColCount += gridControl1_QueryColCount;
gridControl1.QueryRowCount += gridControl1_QueryRowCount;
void gridControl1_QueryColCount(object sender, GridRowColCountEventArgs e)
{
    //Set ColCount for GridControl
    e.Count = int.Parse(colCountText.Text);
    e.Handled = true;
}
void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e)
{
    //Set RowCount for GridControl
    e.Count = int.Parse(rowCountTxt.Text);
    e.Handled = true;
}

VB

//Hook these events to set the RowCol count 
gridControl1.QueryColCount += gridControl1_QueryColCount;
gridControl1.QueryRowCount += gridControl1_QueryRowCount;
Private Sub gridControl1_QueryColCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
     'Set ColCount for GridControl
     e.Count = Integer.Parse(colCountText.Text)
     e.Handled = True
End Sub
Private Sub gridControl1_QueryRowCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
     'Set RowCount for GridControl
     e.Count = Integer.Parse(rowCountTxt.Text)
     e.Handled = True
End Sub

The following screenshot illustrates the output.

Setting the row and column count

Figure 1: Setting the row, col count using QueryRowCount, QueryColCount events

Samples:

C#: SetRowColCount-CS.zip

VB: SetRowColCount-VB.zip

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