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. Image for the cookie policy date

GridControl Rows and Scroll bar

Hi, I have a GridControl in my form. I want to display 10 rows but if the database has 5 records. It should display all 5 records and also display the 5 empty rows. If I have more than 10 records then it should display all the records with the vertical scrollbar. Regards Rajesh

3 Replies

AD Administrator Syncfusion Team January 28, 2005 10:12 AM UTC

I am not sure how you are setting up your GridControl.RowCount property and how you are getting your Datatable data into the GridControl. So, I can only suggest the properties that you can use to do something like this. Whether they will work in your particular situation, I do not know. Here is a code snippet showing how you can set the grid''s client height to be exactly the header rows plus 10 default rows high. For this to work the grid''s height cannot be constrained (like the being docked.Fill or having top and bottom anchored). The snippet also shows how to display empty rows in the clientarea.
private void Form1_Load(object sender, System.EventArgs e)
{
	this.gridControl1.ColCount = 7;
	this.gridControl1.RowCount = 5;//22;
	int h = this.gridControl1.RowHeights.GetTotal(0, this.gridControl1.Rows.HeaderCount)
			+ 10 * this.gridControl1.DefaultRowHeight;
	this.gridControl1.ClientSize = new Size(this.gridControl1.ClientSize.Width, h);
	this.gridControl1.Model.Options.DisplayEmptyRows = true;
}


RA Rajesh January 29, 2005 01:16 AM UTC

Hi, Thanks for your help. But I dont want to change the height of the Grid if the records is more then it should show the Vertical Scroll bar. Regards Rajesh >I am not sure how you are setting up your GridControl.RowCount property and how you are getting your Datatable data into the GridControl. So, I can only suggest the properties that you can use to do something like this. Whether they will work in your particular situation, I do not know. > >Here is a code snippet showing how you can set the grid''s client height to be exactly the header rows plus 10 default rows high. For this to work the grid''s height cannot be constrained (like the being docked.Fill or having top and bottom anchored). The snippet also shows how to display empty rows in the clientarea. > >
>private void Form1_Load(object sender, System.EventArgs e)
>{
>	this.gridControl1.ColCount = 7;
>	this.gridControl1.RowCount = 5;//22;
>	int h = this.gridControl1.RowHeights.GetTotal(0, this.gridControl1.Rows.HeaderCount)
>			+ 10 * this.gridControl1.DefaultRowHeight;
>	this.gridControl1.ClientSize = new Size(this.gridControl1.ClientSize.Width, h);
>	this.gridControl1.Model.Options.DisplayEmptyRows = true;
>}
>


AD Administrator Syncfusion Team January 29, 2005 06:21 AM UTC

The code I suggested always tries to show exactly 10 rows visible whether there are 3 rows in your data or 400 rows in your data. If there were 3 rows, you would not see a vertical scrollbar, but if there were 400 rows (or 11 row) you would. If you do not want to always see 10 rows visible, but just want to grid to have a minimum of 10 rows total (whether they are visible or not), just make sure the RowCount is 10 or larger. (This assumes you are working with a GridControl that holds its own data.) gridControl1.RowCount = Math.Max(10, numberOfRowsInYourDataSource);

Loader.
Up arrow icon