Home Forums WinForms controls Xceed Grid for WinForms Clearing the grid

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12755 |

    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
    GridControl1.Columns.RemoveAt(0)
    End While

    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?

    Thanks,
    Paul

    Imported from legacy forums. Posted by Paul.Chernyakov (had 5901 views)

    User (Old forums)
    Member
    Post 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
    gcOuting.Columns.Remove(gcOuting.Columns.Item(0))
    Next
    gcOuting.DataRows.Clear()

    Imported from legacy forums. Posted by Doc Ozzie (had 442 views)

    User (Old forums)
    Member
    Post 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
    Next
    GridControl1.DataRows.Clear()

    Imported from legacy forums. Posted by Paul.Chernyakov (had 304 views)

    User (Old forums)
    Member
    Post count: 23064

    yes..

    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)
    Member
    Post count: 23064

    and to clear out my datarows.. I used similar methodology..

    For iCTR2 = 0 To gcOuting.DataRows.Count – 1
    gcOuting.DataRows.Remove(gcOuting.DataRows.Item(0))
    Next

    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)
    Member
    Post 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).

    {System.ArgumentOutOfRangeException}
    [System.ArgumentOutOfRangeException]: {System.ArgumentOutOfRangeException}
    Object: {System.ArgumentOutOfRangeException}
    _COMPlusExceptionCode: -532459699
    _className: Nothing
    _exceptionMethod: Nothing
    _exceptionMethodString: Nothing
    _message: “The index must be greater than or equal to 0 and less than Count.”
    _innerException: Nothing
    _helpURL: Nothing
    _stackTrace: {System.Array}
    _stackTraceString: Nothing
    _remoteStackTraceString: Nothing
    _remoteStackIndex: 0
    _HResult: -2146233086
    _source: Nothing
    _xptrs: 0
    _xcode: -532459699
    Message: “The index must be greater than or equal to 0 and less than Count.
    Parameter name: index
    Actual value was 0.”
    InnerException: Nothing
    TargetSite: {System.Reflection.RuntimeMethodInfo}
    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″
    HelpLink: “”
    Source: “Xceed.Grid”
    HResult: -2146233086

    Imported from legacy forums. Posted by Paul.Chernyakov (had 720 views)

    User (Old forums)
    Member
    Post count: 23064

    Looks like you are making this FAR more complex then it really is.

    All I do is
    GridName.DataRows.Clear();

    Bingo, done. Bound or Unbound. 🙂

    -Nick

    Imported from legacy forums. Posted by Buggi (had 554 views)

    User (Old forums)
    Member
    Post 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)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.