Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Deletion via gridview.

Deletion via gridview.

Scheduled Pinned Locked Moved C#
cssdata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Omar Akhtar Sheikh
    wrote on last edited by
    #1

    I am using a data grid view with an unbounded check box column. I am trying to delete those selected values from the grid that are checked through the check boxes only. Can any body plz give me the code for it. Currently I am using the following: <code> private void btnToDeleteSelectedRows_Click(object sender, EventArgs e)                   {                            DALHelper dH = new DALHelper();                            List<int> rowsToDelete = new List<int>();                            int[] array = new int[10];                            for (int i = 0; i < dataGridView1.Rows.Count; i++)                            {                               if (Convert.ToBoolean(dataGridView1["column1", i].Value))                                     {                                              rowsToDelete.Add(i);                                     }                                                                                                    }                                              }

    A S 2 Replies Last reply
    0
    • O Omar Akhtar Sheikh

      I am using a data grid view with an unbounded check box column. I am trying to delete those selected values from the grid that are checked through the check boxes only. Can any body plz give me the code for it. Currently I am using the following: <code> private void btnToDeleteSelectedRows_Click(object sender, EventArgs e)                   {                            DALHelper dH = new DALHelper();                            List<int> rowsToDelete = new List<int>();                            int[] array = new int[10];                            for (int i = 0; i < dataGridView1.Rows.Count; i++)                            {                               if (Convert.ToBoolean(dataGridView1["column1", i].Value))                                     {                                              rowsToDelete.Add(i);                                     }                                                                                                    }                                              }

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Omar, You can try this out,

      foreach (dataGridView1 row in this.dataGridView1.Rows)
      {
      // I have assumned that you 2nd column is the Checbox
      DataGridViewCheckBoxCell Checkedcell = row.Cells[1] as DataGridViewCheckBoxCell;
      if (Checkedcell != null && row.IsNewRow != true)
      {
      this.dataGridView1.Rows.Remove(row);
      }
      }

      Hope this will help you :-D

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      1 Reply Last reply
      0
      • O Omar Akhtar Sheikh

        I am using a data grid view with an unbounded check box column. I am trying to delete those selected values from the grid that are checked through the check boxes only. Can any body plz give me the code for it. Currently I am using the following: <code> private void btnToDeleteSelectedRows_Click(object sender, EventArgs e)                   {                            DALHelper dH = new DALHelper();                            List<int> rowsToDelete = new List<int>();                            int[] array = new int[10];                            for (int i = 0; i < dataGridView1.Rows.Count; i++)                            {                               if (Convert.ToBoolean(dataGridView1["column1", i].Value))                                     {                                              rowsToDelete.Add(i);                                     }                                                                                                    }                                              }

        S Offline
        S Offline
        SajjadZare
        wrote on last edited by
        #3

        for (int i = (dataGridView1.Rows.Count) - 1; i >= 0; i--) if (Boolean.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString())) dataGridView1.Rows.RemoveAt(i); ______________________________________________________________ check box column = cell[2]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups