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

How can I disable the inserting of new rows in the GridControl?

I have looked thru the GridControl documentation and haven't put together how to disable the inserting of new rows. Any help would be appreciated. Thanks.

5 Replies

AR Arulpriya Ramalingam Syncfusion Team May 8, 2017 08:59 AM UTC

Hi Eric, 

Thanks for your interest in Syncfusion products. 

In order to disable the inserting a new row in GridControl ,RowsInserting event can be used. In that event, e.Cancel can be used to avoid inserting a new row in the Grid. Please make use of below code and sample, 

Code snippet 
 
//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; 
} 

 

Regards, 
Arulpriya


EH Eric Huning May 8, 2017 03:05 PM UTC

Thank you for the information. I saw in the samples where the CellStartEditing event would disable editing also. 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. Thanks.


AR Arulpriya Ramalingam Syncfusion Team May 9, 2017 12:06 PM UTC

Hi Eric, 
 
Thanks for your update. 
 
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; 
 
 
 
Regards, 
Arulpriya 



EH Eric Huning May 9, 2017 02:19 PM UTC

Thank you, my grid works great! 


AR Arulpriya Ramalingam Syncfusion Team May 10, 2017 04:02 AM UTC

Hi Eric,   
 
We are glad to hear that the provided solution is resolved your scenario.   
 
Please let us know if you need any further assistance.    
   
Regards,   
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon