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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

130333 May 7,2017 04:06 PM UTC May 10,2017 04:02 AM UTC WinForms 5
loading
Tags: GridControl
Eric Huning
Asked On May 7, 2017 04:06 PM UTC

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.

Arulpriya Ramalingam [Syncfusion]
Replied On 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

Eric Huning
Replied On 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.

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


Eric Huning
Replied On May 9, 2017 02:19 PM UTC

Thank you, my grid works great! 

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;