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
close icon

Adding/Removing Rows from a Virtual Grid

I am attempting to programmatically add and remove rows from a Virtual Grid. Incrementing the RowCount property of the GridControl does not work. Similarly, decrementing the RowCount property of the GridControl does not work either. The main reason for doing this programmatically is to take advantage of the undo/redo functionality of the grid when adding/removing rows. Jason

5 Replies

AD Administrator Syncfusion Team December 2, 2003 04:00 PM UTC

In a virtual grid, you will have to manage adding and removing rows from your external datasource. The virtual grid just displays the data in your datasource. So, if you want a row removed, you have to remove it from the datasource. Normally, in a virtual grid, you do not explicitly set grid.RowCount = xxxx. Instead, you use the grid.QueryRowCount event and dynamically provide the row by setting e.Size and e.Handled, based on e.Index that comes in. Normally, you would set e.Size directly from the external data source in some manner. If you do this, then if you add a row to your external data or remove a row from the external data, the grid will automatically know the proper row count. (You may have to call grid.Refresh after you modify the row count in your external data source, but that should be it). When the grid is drawn the next time, it should reflect the changed data.

JT Jason Thompson December 3, 2003 11:20 AM UTC

I had tried what you suggested (modifying the source data and calling refresh), but it doesn''t assist me in accomplishing my goal. It would be nice to be able to programmatically add or remove a row within a virtual grid that also was placed on the commandstack. The Undo/Redo functionality is a necessity.

AD Administrator Syncfusion Team December 3, 2003 12:53 PM UTC

You would have to create Custom Undo commands that have actually have everything needed to undo and redo the actions you want to handle. So, if you want to undo adding/removing a row from your data source, you would derive from GridModelCommand. In your derived class, you would add whatever properties/structures you need to be able to undo and redo this add/remove action. Then you would also override the Execute method to actually perform the undo action. If you have the source code, you can see how the grid does this type of thing. Do a search on GridModelSetCoveredRangesCommand for example. This will show you how the class is implemented, and then how an instance of it is added to the CommandStack when covered cells are set. If you search for GridModelCommand in the source code, you will see all the undo actions supported as their commands all derive from GridModelCommand.

JT Jason Thompson December 4, 2003 11:42 AM UTC

Would it be possible for me to fake a GridModelInsertRangeCommand and a GridModelRemoveRangeCommand for my Remove/Add operations? You would think that it would be possible; however, the documentation provided for those class is extrememly sparse. Jason

JT Jason Thompson December 4, 2003 12:14 PM UTC

Nevermind. Those commands are apparently only applicable to Bound Grids. Jason

Live Chat Icon For mobile
Up arrow icon