locked
Delete all Rows from DataGridview RRS feed

  • Question

  • i have a datagridview and it has many rows in it i wanna click button

    the delete all the rows in the datagrid not only one row by every click

    Friday, June 24, 2011 2:36 PM

Answers

  • 1. Unboud dataGridView:

    dataGridView1.Rows.Clear();
    


    2. bound (clear the dataSource):

    dataTable.Rows.Clear();
    

    or you can even set dataSource to null (dt = null;)


    Mitja
    Friday, June 24, 2011 2:56 PM
  • Hi

    just add button and on its event handler write this

    dataGridView1.Rows.Clear();

    this will delete rows  from your gride


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 24, 2011 4:33 PM

All replies

  • Hello,

    You want to delete from the grid or delete them from the source of the grid?

    Adam


    Ctrl+Z
    Friday, June 24, 2011 2:47 PM
  • 1. Unboud dataGridView:

    dataGridView1.Rows.Clear();
    


    2. bound (clear the dataSource):

    dataTable.Rows.Clear();
    

    or you can even set dataSource to null (dt = null;)


    Mitja
    Friday, June 24, 2011 2:56 PM
  • Hi

    just add button and on its event handler write this

    dataGridView1.Rows.Clear();

    this will delete rows  from your gride


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 24, 2011 4:33 PM
  • 1. Unboud dataGridView:

     

    dataGridView1.Rows.Clear();
    

     


    2. bound (clear the dataSource):

     

    dataTable.Rows.Clear();
    

    or you can even set dataSource to null (dt = null;)

     


    Mitja

    Addition, if you want to delete all the data from database, you can use T-SQL like this:

                    Delete * from table.

    Thanks.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 28, 2011 5:48 AM
    Moderator