Lets say, we have 10 columns in one datagridview. I have 20 rows of data in these 10 columns.
Dynamically, I’m hiding (setting the .Visible property of the column to false) a few columns – say column 1, 2, 4, 5.
Now I want to copy the contents of the columns which are visible (20 rows of data, 6 visible columns – 3, 6, 7, 8, 9, 10) to a new datagridview.
Any suggestions / advise / links?
I’ve researched this forum and could not find a post discussing about copying a subset of columns from one datagridview to another.
thanks.
Try this (you didn’t indicate whether it was ASP.NET, WinForms, etc – this example is based on WinForms). Christian’s suggestion above is in the right direction, but when I tried it out
Clone()didn’t copy the values, and I couldn’t see a way to get it to do that.I’ll admit this is ugly and rather brute force, but I tested it and it worked. There may be better ways to do it, but this should at least help you some, I hope.