//Event Triggering
this.gridControl1.Model.RowsInserting += Model_RowsInserting;
//Event Customization
private void Model_RowsInserting(object sender, GridRangeInsertingEventArgs e)
{
if (this.gridControl1.RowCount > 15)
e.Cancel = true;
} |
Query |
Response |
What I would like to know is if there is a way to prevent the grid control from display an empty line used for inserting new rows. Displaying only the rows that I have in the table would look cleaner. |
Suggestion 1
In order to prevent inserting the empty rows and columns, QueryRowHeight and QueryColWidth events can be used. In that event, the empty rows can be hidden by using Size property. Please make use of below code and sample,
//Event Triggering
gridControl1.QueryRowHeight += GridControl1_QueryRowHeight;
//Event Customization
private void GridControl1_QueryRowHeight(object sender, GridRowColSizeEventArgs e)
{
if (e.Index > dataTable.Rows.Count)
{
e.Size = 0;
e.Handled = true;
}
} |
Suggestion 2
Inserting the empty rows can also be prevented by setting the number of rows in the data source to RowCount of the Grid. Please make use of below code,
//To set the data source row count to row count
gridControl1.RowCount = dataTable.Rows.Count;
gridControl1.ColCount = dataTable.Columns.Count;
|