Home Forums WinForms controls Xceed Grid for WinForms How do I delete multiple rows

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

    Hi

    I am using the following code to delete a row.

    grdBOM.DataRows.Remove(CType(grdBOM.CurrentRow, Xceed.Grid.DataRow))

    Is it possible to modify this to delete multiple rows if they are selected?

    Thanks

    Nick

    Imported from legacy forums. Posted by Nick (had 5950 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m a C#-programmer, so my VB-code might not be 100% correct, but it should look like this:<code>For Each Xceed.Grid.DataRow row in grdBOM.SelectedRows Do
    grdBOM.DataRows.Remove(row)
    Next</code>

    Imported from legacy forums. Posted by Tommy (had 349 views)

    User (Old forums)
    Member
    Post count: 23064

    Pretty darn close Tommy!

    Here’s your VB.Net code (if you still required it)

    Dim myRow As Xceed.Grid.DataRow
    For Each myRow In grdControl1.SelectedRows
    grdControl1.DataRows.Remove(myRow)
    Next

    Or if you prefer more compact code you could also have done this:

    For Each myRow as Xceed.Grid.DataRow In grdControl1.SelectedRows
    grdControl1.DataRows.Remove(myRow)
    Next

    -LK

    Imported from legacy forums. Posted by Curtis (had 696 views)

    User (Old forums)
    Member
    Post count: 23064

    That’s the trouble with coding blind…you always forget the simpliest things!

    If you were to try and execute the code I posted – you’re going to get a runtime error (sorry about that ! )

    Why? Because the collection (SelectedRows) will become modified the instant you perform a remove on the DataRows collection…and that will cause the For…Next loop to fail.

    I’m working on a solution to this right now – and would have edited my previous post instead of adding this new one…but since I could not, this’ll have to do!

    -LK

    Imported from legacy forums. Posted by Curtis (had 708 views)

    User (Old forums)
    Member
    Post count: 23064

    For t As Integer = Me.GridControl1.SelectedRows.Count – 1 To 0
    Me.GridControl1.SelectedRows(t).Remove()
    Next

    Imported from legacy forums. Posted by Kevin (had 373 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry, code should be

    For t As Integer = Me.GridControl1.SelectedRows.Count – 1 To 0 Step -1
    Me.GridControl1.SelectedRows(t).Remove()
    Next


    Kev

    Imported from legacy forums. Posted by Kevin (had 451 views)

    User (Old forums)
    Member
    Post count: 23064

    This is how it should be in C#:
    <b>
    for (int i = gridControl1.SelectedRows.Count-1; i>=0; i–)
    {
    gridControl1.SelectedRows[i].Remove();
    }
    </b>

    Imported from legacy forums. Posted by Nathan (had 361 views)

    User (Old forums)
    Member
    Post count: 23064

    How could I delete all the rows in one group?

    I can get the rows by group.GetSortedDataRows(false) but I’m still getting errors when deleting them.

    Imported from legacy forums. Posted by sebastian (had 542 views)

    User (Old forums)
    Member
    Post count: 23064

    I figured it out:

    For example you can catch the key down event for the delete key and then handle it diffently for normal DataRows or GroupManagerRows or whatever.

    The code below is for deleting a group:

    private void deleteGroup( GroupManagerRow row )
    {

    ReadOnlyDataRowList groupRows = row.ParentGroup.GetSortedDataRows(false);
    for (int i= groupRows.Count-1; i>=0; i–)
    {
    groupRows[i].Remove();
    }

    }

    Imported from legacy forums. Posted by sebastian (had 6761 views)

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