Forums

DeleteRow

Last post 11/5/2004 1:09 PM by Developer Express Inc - Alex . 2 replies.
Sort Posts: Previous Next
  • Brian Hansen

    DeleteRow

    11/3/2004 3:25 PM
    Hi
    
    I'm trying to delete some rows from a grid. I use the following code (taken
    from the help)
    
    private void DeleteRows()
    
    {
    
        int[] selectedRows = GridView.GetSelectedRows();
    
        if(selectedRows != null)
    
        {
    
            try
    
            {
    
                GridView.BeginUpdate();
    
                Array.Sort(selectedRows);
    
                for (int i=selectedRows.Length-1; i>=0; --i)
    
                {
    
                    GridView.DeleteRow(selectedRows[i]);
    
                }
    
            }
    
            finally
    
            {
    
                GridView.EndUpdate();
    
            }
    
        }
    
    }
    
    I have a Grid with a DataSource with 3 rows. If I select row no. 1 and 3 in
    that order and invokes the method, then I can't select the remaining row. I
    get a DialogBox saying "Index was out of range. Must be non-negative and
    less than the size of the collection. Parameter name: index Do you want to
    correct the value ?".
    
    If I select row no. 3 and then no. 1 there is no problem!
    
    What am I doing wrong??
    
    
    
    Thanks for your help!
    
    Brian
  • Brian Hansen

    Re: DeleteRow

    11/4/2004 12:58 PM
    After removing the 2 rows the FocusedRowHandle is 1 even though there is
    only 1 row left in the grid and therefore should be 0.
    
    Can anyone help me on this??
    
    "Brian Hansen" <bsh@git.dk> skrev i en meddelelse
    news:4188f851@news.devexpress.com...
    > Hi
    >
    > I'm trying to delete some rows from a grid. I use the following code
    (taken
    > from the help)
    >
    > private void DeleteRows()
    >
    > {
    >
    >     int[] selectedRows = GridView.GetSelectedRows();
    >
    >     if(selectedRows != null)
    >
    >     {
    >
    >         try
    >
    >         {
    >
    >             GridView.BeginUpdate();
    >
    >             Array.Sort(selectedRows);
    >
    >             for (int i=selectedRows.Length-1; i>=0; --i)
    >
    >             {
    >
    >                 GridView.DeleteRow(selectedRows[i]);
    >
    >             }
    >
    >         }
    >
    >         finally
    >
    >         {
    >
    >             GridView.EndUpdate();
    >
    >         }
    >
    >     }
    >
    > }
    >
    > I have a Grid with a DataSource with 3 rows. If I select row no. 1 and 3
    in
    > that order and invokes the method, then I can't select the remaining row.
    I
    > get a DialogBox saying "Index was out of range. Must be non-negative and
    > less than the size of the collection. Parameter name: index Do you want to
    > correct the value ?".
    >
    > If I select row no. 3 and then no. 1 there is no problem!
    >
    > What am I doing wrong??
    >
    >
    >
    > Thanks for your help!
    >
    > Brian
    >
    >
  • Developer Express Inc - Alex

    Re: DeleteRow

    11/5/2004 1:09 PM
    Hi Brian,
    
    I've tried this code with the latest version (2.4.4) of the XtraGrid and it 
    worked fine for me. Please check that you are using the latest version of 
    the XtraGrid and if it still doesn't work, please send a sample project to 
    our support team.
    
    -- 
    Alex
    
    R&D, .NET Team
    Developer Express Inc.
    
    PS. Please don't reply to me by email directly unless it is specifically
    requested.
    If you wish to receive direct assistance from our Support Team, feel free to
    contact us at Support@DevExpress.com.
    
    "Brian Hansen" <bsh@git.dk> wrote in message 
    news:418a2777$1@news.devexpress.com...
    > After removing the 2 rows the FocusedRowHandle is 1 even though there is
    > only 1 row left in the grid and therefore should be 0.
    >
    > Can anyone help me on this??
    >
    > "Brian Hansen" <bsh@git.dk> skrev i en meddelelse
    > news:4188f851@news.devexpress.com...
    >> Hi
    >>
    >> I'm trying to delete some rows from a grid. I use the following code
    > (taken
    >> from the help)
    >>
    >> private void DeleteRows()
    >>
    >> {
    >>
    >>     int[] selectedRows = GridView.GetSelectedRows();
    >>
    >>     if(selectedRows != null)
    >>
    >>     {
    >>
    >>         try
    >>
    >>         {
    >>
    >>             GridView.BeginUpdate();
    >>
    >>             Array.Sort(selectedRows);
    >>
    >>             for (int i=selectedRows.Length-1; i>=0; --i)
    >>
    >>             {
    >>
    >>                 GridView.DeleteRow(selectedRows[i]);
    >>
    >>             }
    >>
    >>         }
    >>
    >>         finally
    >>
    >>         {
    >>
    >>             GridView.EndUpdate();
    >>
    >>         }
    >>
    >>     }
    >>
    >> }
    >>
    >> I have a Grid with a DataSource with 3 rows. If I select row no. 1 and 3
    > in
    >> that order and invokes the method, then I can't select the remaining row.
    > I
    >> get a DialogBox saying "Index was out of range. Must be non-negative and
    >> less than the size of the collection. Parameter name: index Do you want 
    >> to
    >> correct the value ?".
    >>
    >> If I select row no. 3 and then no. 1 there is no problem!
    >>
    >> What am I doing wrong??
    >>
    >>
    >>
    >> Thanks for your help!
    >>
    >> Brian
    >>
    >>
    >
    > 
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.