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

Correct way to remove all rows i a grid?

Thread ID:





19351 Sep 24,2004 04:08 AM UTC Sep 24,2004 10:42 AM UTC WinForms 3
Tags: GridControl
Peter Erikson
Asked On September 24, 2004 04:08 AM UTC

if (m_grid.Model.RowCount != 0) m_grid.Rows.RemoveRange(1, m_grid.Model.RowCount);

Peter Erikson
Replied On September 24, 2004 04:15 AM UTC

Sorry accidently posted the prevoius post before it was finished. Well, my question is... Wich is the right way to remove all rows in a GridControl? I am using this method : if (m_grid.Model.RowCount != 0) m_grid.Rows.RemoveRange(1, m_grid.Model.RowCount); I often get a NullReferenceExeption doing it this way. see below. catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.Validate() in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridModelRowOperations.RaiseRemoving(GridRangeRemovingEventArgs e) in :line 0 An unhandled exception of type ''System.NullReferenceException'' occurred in syncfusion.grid.dll Is there a right way of doing it? or can it be something else in my code that causes the exeption? Thanx. /Peter

Administrator [Syncfusion]
Replied On September 24, 2004 09:49 AM UTC

Hi Peter, are you handling any validating events? Something must be happening along these lines in CurrentCell.Validate: // possibly shows a dialog box (but user can also set CurrentCell.ErrorMessage) IsValid = Grid.RaiseCurrentCellValidating() && cellRenderer.RaiseValidate(); if (IsValid) { cellRenderer.RaiseValidated(); Grid.RaiseCurrentCellValidated(); } By the time CurrentCellValidating the renderer seems to be gone because the current cell was deactivated. We''ll add a null reference check to avoid this being a problem in our code for future builds. But, what you can do for now is simply call CurrentCell.Deactivate() before you call RemoveRange. That way there is no current cell to start with and above Validate code will not get hit at all during the RemoveRange operation. Stefan

Peter Erikson
Replied On September 24, 2004 10:42 AM UTC

Hi Stefan, Thanx for the info on this and the fast response. You are probarbly right regarding the Cell validaton. And that that is the source of the problem. I´ll se if the CurrentCell.Deactivate solution fixes it. Thanx!


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon