How do you cache a row without raising a “Row provided already belongs to a DataGridView” error?

Once a row is part of a gridview, you can't re-add it. The row itself keeps track of what DataGridView it is in. I would suggest making a copy of the cached row and adding the copy to the view.

Since you make a new copy each time it won't be in the view. Alternatively, you can go through and remove only those rows that have not been cached from the view, leaving the cached rows behind so that you don't need to re-add it.

The link given is to a DataRow method, not a DataGridViewRow method. Is this also the case for DataGridViewRows as well? – Brendan Feb 28 '09 at 23:48 Sorry.

The principle is the same -- it does keep track. I've updated the post and link. – tvanfosson Mar 1 '09 at 1:09.

You should only remove the rows in the grid that you want to remove. You should look into implementing ObservableCollection and a Binding component. This way, if an item is removed from your object model, then it is automatically removed from the grid.

This saves you having to perform what sounds like manual data binding and avoids this problem altogether. If you're using DataSet or typed DataSets, then the observable functionality is already implemented for you - you just need to bind the datatable to the grid. If you have a table object in memory, you'll notice that you can load another one, then use the DataTable.

Merge function to combine the results.

My dialog previews a CSV file of numerical data in a read-only DataGridView. If the headers are not in the preview it can include an editable line where the user can input their own headers. This may be switched off/on and needs to be cached in these cases – Brendan Mar 1 '09 at 18:51 In that case, I'd always filter the headers out of the input prior to binding, and use the file contents to build actual column headers for the grid.

– Neil Barnwell Mar 2 '09 at 8:16 The dialog is one to parse an arbitrary CSV file, the file may not include headers at all - hence the option to add some. I tried using a separate cache list of cell contents but it turned out to be a lot of hassle keeping the two concurrent. – Brendan Mar 2 '09 at 10:16.

Clone it to a DataRow() and then DataTable. ImportRow to the originating DataTable.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions