Delete Selected Rows

11 posts, 1 answers
  1. Dan
    Dan avatar
    9 posts
    Member since:
    Jul 2008

    Posted 23 Jul 2008 Link to this post

    Hi,
    Prob a simple question
    Is there an option for deleting selected rows via code
    Something like "Grid.SelectedRows.Delete"

    If not Can you show me how plz.

    Thanks in advance.
  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 25 Jul 2008 Link to this post

    Hi Dan,

    You can use following code snippet:

    private void boundRadButton_Click(object sender, EventArgs e) 
        if (this.radGridView1.SelectedRows.Count > 0) 
        { 
            GridViewDataRowInfo[] rows = new GridViewDataRowInfo[this.radGridView1.SelectedRows.Count]; 
            this.radGridView1.SelectedRows.CopyTo(rows, 0); 
     
            this.radGridView1.GridElement.BeginUpdate(); 
     
            for (int i = 0; i < rows.Length; i++) 
            { 
                rows[i].Delete(); 
            } 
     
            this.radGridView1.GridElement.EndUpdate(); 
        } 

    I hope this helps. Don't hesitate to write us back if you have other questions.

    Sincerely yours,
    Julian Benkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Mark
    Mark avatar
    9 posts
    Member since:
    Jul 2008

    Posted 05 Dec 2008 Link to this post

    Delete is not an available method in GridViewDataRowInfo[] for Q2.  What suggestions do you have for Q2?  Upgrading is not an option.
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 08 Dec 2008 Link to this post

    Hello Mark,

    Sorry for my omission. You can use the following snippet:

    private void boundRadButton_Click(object sender, EventArgs e)  
    {  
        if (this.radGridView1.SelectedRows.Count > 0)  
        {  
            GridViewDataRowInfo[] rows = new GridViewDataRowInfo[this.radGridView1.SelectedRows.Count];  
            this.radGridView1.SelectedRows.CopyTo(rows, 0);  
      
            this.radGridView1.GridElement.BeginUpdate();  
      
            for (int i = 0; i < rows.Length; i++)  
            {  
                this.radGridView1.Rows.Remove(rows[i]); 
            }  
      
            this.radGridView1.GridElement.EndUpdate();  
        }  
    }  


    Sincerely yours,
    Julian Benkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 05 Jun 2009 Link to this post

    I can't see how this code snippet will work, as it appears to delete the first couple of rows in the GridView and NOT the selected rows.

    I know this post is for 2008 Q2 (?) and I'm using 2009 Q1.

    What I'm trying to achieve is to delete all of the selected rows from a data bound GridView.

    Regards.
  6. Victor
    Admin
    Victor avatar
    1358 posts

    Posted 05 Jun 2009 Link to this post

    Hello Richard Slade,

    Thank you for your question.

    The snippet copies the selected rows to an array and then removes them from RadGridView one by one. May be you are after a different behavior? What do you mean by "it appears to delete the first couple of rows"?
     

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Sunil
    Sunil avatar
    11 posts
    Member since:
    May 2009

    Posted 24 Sep 2009 Link to this post

    Hi I am using version Q3 2008 win control library.
    I am using this code in my form. It sometimes deleted the rows from the radGridView but sometime not.....
    Do I need to make special settings in design time or runt time?
  8. Sunil
    Sunil avatar
    11 posts
    Member since:
    May 2009

    Posted 24 Sep 2009 Link to this post

    In continuation to my previous post..
    I am able to delete the selected radGridview rows when i drop the radGridview in windows form. But when i drop it on the System.Windows.Forms.TabControl, selected rows are not deleted.
    Thanx in advance...


  9. Victor
    Admin
    Victor avatar
    1358 posts

    Posted 29 Sep 2009 Link to this post

    Hello Sunil,

    Thank you for writing. I tested the described behavior with the latest build and it behaves correctly. You can upgrade to the latest version or if this is not feasible please send a sample application so that I may debug it and provide a solution. I am looking forward to your reply.

    Kind regards,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Gh Reza
    Gh Reza avatar
    12 posts
    Member since:
    Jul 2011

    Posted 11 Apr 2020 Link to this post

    Hi

    I have  problem in deleting row in data bound mode. i do bind gridView to bindingSource like: 

    radGridView.datasource = bindingSource1;

    When i delete a row at runtime , the selected row remove from binding source. in UserDeletingRow event i change the selected row state to Deleted state like : 

      row.Cells["EntityState"].Value = EntityState.Deleted;

    finally i send bindingsource list to my entityframework repository for CRUD operations but my selected row in binding list deleted automatically and i lost that row must delete and  finally the row never physically delete from database.

    please help me.

    thank you

     

     

     

  11. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4169 posts

    Posted 13 Apr 2020 Link to this post

    Hello, Reza,

    Please refer to the following help article demonstrating how to update the database once a row gets added/updated or deleted: https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/updating-the-database-with-ado.net 

    I hope this information helps. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top