How to set the number of rows and columns in a WinForms GridControl?
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
// set RowCount for GridControl
gridControl1.RowCount = 20;
// set ColCount for GridControl
gridControl1.ColCount = 120;' set RowCount for GridControl
gridControl1.RowCount = 20
' set ColCount for GridControl
gridControl1.ColCount = 120Using
Events
The events QueryRowCount and QueryColCount are used to set the count for rows and columns.
//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;
}'Hook these events to set the RowCol count
AddHandler gridControl1.QueryColCount, AddressOf gridControl1_QueryColCount
AddHandler gridControl1.QueryRowCount, AddressOf 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 SubThe following
screenshot illustrates the output.

Figure 1: Setting the row, col count using QueryRowCount, QueryColCount events
Samples:
Conclusion
I hope you enjoyed learning about how to set the number of rows and columns in a WinForms GridControl.
You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!