locked
how to perform delete operation on gridview in C# .net RRS feed

  • Question

  • how to perform delete operation on gridview in C# .net
    Thursday, June 20, 2013 4:46 AM

Answers

  • If you want to delete all the rows simply call the dataview consructor

    myGridView = new GridView()

    Are you trying to delete one row or just some items in a cell(s)?  Listview are not easy to work with and I would need to see how you are adding the itmes to determine the best method for deleting.  I've seen a case a couple of weeks ago that the person thought the data was going into multiple columns when the data was acutally only going into one column.  Try enabling the girdlines to make sure you data is in more than one column.


    jdweng

    • Marked as answer by Bob Shen Tuesday, July 2, 2013 9:48 AM
    Thursday, June 20, 2013 6:56 AM
  • If you are able to access the DataGridView object, you can simply call the RemoveAt method.

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
     {
      dataGridview1.Rows.RemoveAt[e.RowIndex];
     }


    • Proposed as answer by L Mateijsen Thursday, June 20, 2013 8:10 AM
    • Marked as answer by Bob Shen Tuesday, July 2, 2013 9:48 AM
    Thursday, June 20, 2013 8:10 AM

All replies

  • how to perform delete operation on gridview in C# .net

    Thursday, June 20, 2013 4:47 AM
  • If you want to delete all the rows simply call the dataview consructor

    myGridView = new GridView()

    Are you trying to delete one row or just some items in a cell(s)?  Listview are not easy to work with and I would need to see how you are adding the itmes to determine the best method for deleting.  I've seen a case a couple of weeks ago that the person thought the data was going into multiple columns when the data was acutally only going into one column.  Try enabling the girdlines to make sure you data is in more than one column.


    jdweng

    • Marked as answer by Bob Shen Tuesday, July 2, 2013 9:48 AM
    Thursday, June 20, 2013 6:56 AM
  • If you are able to access the DataGridView object, you can simply call the RemoveAt method.

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
     {
      dataGridview1.Rows.RemoveAt[e.RowIndex];
     }


    • Proposed as answer by L Mateijsen Thursday, June 20, 2013 8:10 AM
    • Marked as answer by Bob Shen Tuesday, July 2, 2013 9:48 AM
    Thursday, June 20, 2013 8:10 AM