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

Grid Exception on grid.RowCount--

I am trying to remove a row from a virtual grid and I am getting an exception in the grid. Here is my code: _g.BeginUpdate(); _g.RowCount--; _g.EndUpdate(); I have put the exception that i see below: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: rowIndex at Syncfusion.Collections.SFTable.RemoveRows(Int32 rowIndex, Int32 count) at Syncfusion.Windows.Forms.Grid.GridData.RemoveRows(Int32 rowIndex, Int32 count) at Syncfusion.Windows.Forms.Grid.GridModelRowOperations.DataRemoveRange(Int32 removeAt, Int32 count) at Syncfusion.Windows.Forms.Grid.GridModelRowColOperations.RemoveRange(Int32 from, Int32 last) catched at Syncfusion.Windows.Forms.Grid.GridModelRowColOperations.RemoveRange(Int32 from, Int32 last) in :line 0 thanks, ak

8 Replies

AD Administrator Syncfusion Team August 20, 2005 01:42 AM UTC

In a true virtual grid, you normally never work with grid.RowCount. Instead, you use the grid.QueryRowCount event, and there provide e.Size based on your external data source. If you want to try to explicitly set RowCount, you can. But if you have large numbers of rows, this will defeat part of the purpose of using a virtual grid. And if you are using RowCount, then doing RowCount-- will not change anything in your data source. Maybe calling grid.Refresh() after calling grid.EndUpdate will avoid th eexception you are seeing.


AK Adam K. August 20, 2005 12:21 PM UTC

thanks . . i now understand and removed all increments of row count and col count and replaced them with grid.refresh (to then cause a QueryRowCount and QueryColCount event . .) just a quick question . . do you put the refresh after the endupdate or visa versa . . for example, which is the right way to do this Choice 1: grid.BeginUpdate(); [update data structures that are reference in QueryColCount and QueryRowCount] grid.Refresh(); grid.EndUpdate(); Choice 2: grid.BeginUpdate(); [update data structures that are reference in QueryColCount and QueryRowCount] grid.EndUpdate(); grid.Refresh(); thks, ak >In a true virtual grid, you normally never work with grid.RowCount. Instead, you use the grid.QueryRowCount event, and there provide e.Size based on your external data source. > >If you want to try to explicitly set RowCount, you can. But if you have large numbers of rows, this will defeat part of the purpose of using a virtual grid. And if you are using RowCount, then doing RowCount-- will not change anything in your data source. Maybe calling grid.Refresh() after calling grid.EndUpdate will avoid th eexception you are seeing.


AD Administrator Syncfusion Team August 20, 2005 01:03 PM UTC

You would do 2, after the EndUpdate call.


EC ecosoft August 26, 2005 11:46 PM UTC

Hi, I''m having a similar problem. I have a GridControl with RowCount = 10 (default). However I use QueryRowCount event to set the number of rows, it happens that if I set e.Count = 15 everytime I try to enter a value on a cell I get the exception: "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: rowIndex" (the message is shown in spanish like a dialog box). If I set RowCount with a greater value than the one I set in QueryRowCount everything works fine. Is this a bug or something I am missing? Thanks in advance.


AD Administrator Syncfusion Team August 27, 2005 12:55 AM UTC

The RowCount = 10 is set as a default during the initial setup. And at some point during (or maybe after setup) you subscribe to the QueryRowCount event where you start providing 15 as the RowCount. To make sure this new value is being used, at some point in your code after you subscribe to QueryRowCount and before you start trying to access the extra rows, you need to call grid.ResetVolatileData. (So, just call it immediately afer subscribing to the event). Also, make sure in QueryRowCount, you set e.Handled = true when you set e.Count.


EC ecosoft August 29, 2005 04:14 PM UTC

Thanks. It is right if using QueryCellInfo to populate values, however the exception still appears whenever I try to edit (manually, when running) the cell''s value in extra rows (no matter if I suscribe or not to SaveCellInfo). I enter the value and try to move to another cell and the exception raises. I attach the small sample I''ve tested with. test_syngridcontrol_325.zip


AD Administrator Syncfusion Team August 29, 2005 04:44 PM UTC

If you want to type into a cell and change the value in a virtual grid (and have the grid remember the changed value), then you must have dataSource that holds these values outside the grid. You must handle SaveCellInfo and move teh changed value from teh style to the datasource and set e.Handled = true. And in QueryCellInfo, you must move the data from the datasource to the style. Here is your sample back with these changes. You can type into any cell without seeing an error. http://www.syncfusion.com/Support/user/uploads/test_syngridcontrol_d423009c.zip Now if you just want to type into a cell, and have teh grid lose teh value when you move off teh cell, then you do not need the datasource. ALl you need to do is to handle SaveCellInfo and set e.Handled = true. Setting e.Handled= true tells the grid not to try to save teh value in the grid internal storage. The reason you see an error in your sample when you type after row 10 is that the grid is still trying to save the value in its internal storage because you did not handle SaveCellInfo and set e.Handled = true.


EC ecosoft August 29, 2005 05:30 PM UTC

Actually, I do have an external dataSource to hold data (based on virtual grid tutorials), anyway the problem solved by setting e.Handled = true in SaveCellInfo (which I didn''t set in every case). Thanks a lot.

Loader.
Live Chat Icon For mobile
Up arrow icon