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

Correct way to remove all rows i a grid?

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

3 Replies

PE Peter Erikson 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

AD Administrator Syncfusion Team 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

PE Peter Erikson 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!

Live Chat Icon For mobile
Up arrow icon