User (Old forums)MemberNovember 6, 2003 at 4:58 pmPost count: 23064
I’m trying to clear an unbound grid. I’ve tried several methods, including using the Clear method on the grid itself, on the Columns collection, and on the DataRows collection. After doing so, the count for all the collections is 0, but when I try to add data to the cleared grid (the same data that was there before I cleared it), I get an error stating that “An attempt was made to add an existing column to a ColumnList.”
I’ve also tried:
While GridControl1.Columns.Count > 0
That gives the following error: “The index must be greater than or equal to 0 and less than Count.” However, of course the index is 0 and the count, at the time, is non-zero.
Anyone have any idea what I’m doing wrong?
Imported from legacy forums. Posted by Paul.Chernyakov (had 5901 views)User (Old forums)MemberNovember 7, 2003 at 1:27 pmPost count: 23064
I do this.. and it works fine..
I had to remove the datarows I think to make this work. But, I had the same problem as you.
gcOuting is my “GridControl” name
Dim iCTR As Int32 = 0
For iCTR = 0 To gcOuting.Columns.Count – 1
Imported from legacy forums. Posted by Doc Ozzie (had 442 views)User (Old forums)MemberNovember 7, 2003 at 1:59 pmPost count: 23064
Thank you for your response. I tried what you suggested, and I still get an exception on the Remove() call: “The index must be greater than or equal to 0 and less than Count.” Which is what I was getting before.
Dim i As Integer
For i = 0 To GridControl1.Columns.Count – 1
GridControl1.Columns.Remove(GridControl1.Columns.Item(i)) ‘<—- Exception here
Imported from legacy forums. Posted by Paul.Chernyakov (had 304 views)User (Old forums)MemberNovember 7, 2003 at 2:13 pmPost count: 23064
put a 0 instead of i…
GridControl1.Columns.Remove(GridControl1.Columns.Item(i)) <— make i = 0 dont use the i
what this does is always removes the first column in the collection.
Imported from legacy forums. Posted by Doc Ozzie (had 337 views)User (Old forums)MemberNovember 7, 2003 at 2:17 pmPost count: 23064
and to clear out my datarows.. I used similar methodology..
For iCTR2 = 0 To gcOuting.DataRows.Count – 1
notice, I am always using the first element in the datarows.item(0). I am not incrementing it with iCTR2 or what you were using ‘i’.. Just allow the loop to always remove the first datarow object by keeping it ‘Datarows.item(0)’
Imported from legacy forums. Posted by Doc Ozzie (had 480 views)User (Old forums)MemberNovember 7, 2003 at 2:32 pmPost count: 23064
Oops, silly mistake on my part. However, even with the 0 instead of i, I get the same Exception. It must be something I’m doing, but the only code being run when I clear the grid is the code I pasted (after fixing the above-mentioned error).
_message: “The index must be greater than or equal to 0 and less than Count.”
Message: “The index must be greater than or equal to 0 and less than Count.
Parameter name: index
Actual value was 0.”
StackTrace: ” at Xceed.Utils.Exceptions.ThrowException.ThrowArgumentOutOfRangeException(String paramName, Object value, String message)
at Xceed.Utils.Collections.ListBase.ListGetItem(Int32 index)
at Xceed.Grid.Collections.CellList.get_Item(Int32 index)
at Xceed.Grid.CellRow.RemoveCell(Column column)
at Xceed.Grid.DataManager.RemoveColumn(Column column)
at Xceed.Grid.GridControl.RemoveColumnFromRows(Column column)
at Xceed.Grid.Collections.ColumnList.OnRemoveComplete(Int32 index, Object value)
at Xceed.Utils.Collections.ListBase.InternalRemoveAt(Int32 index)
at Xceed.Utils.Collections.ListBase.InternalRemove(Object value)
at Xceed.Utils.Collections.ListBase.ListRemove(Object value)
at Xceed.Grid.Collections.ColumnList.Remove(Column value)
at xceedwrklst.Form1.ClearGrid() in C:\misc\xceedwrklst\xceedwrklst\Form1.vb:line 363″
Imported from legacy forums. Posted by Paul.Chernyakov (had 720 views)User (Old forums)MemberNovember 13, 2003 at 5:49 pmPost count: 23064
Looks like you are making this FAR more complex then it really is.
All I do is
Bingo, done. Bound or Unbound. 🙂
Imported from legacy forums. Posted by Buggi (had 554 views)User (Old forums)MemberJune 3, 2005 at 1:25 pmPost count: 23064
I just ran into the same problem and after much frustration, I noticed my error……
I had a error in my code in one of the events which I registered with the grid control. Ensure you verify all the code in the events are also valid.
Imported from legacy forums. Posted by Shawn (had 6685 views)
- You must be logged in to reply to this topic.