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
  1. Home
  2. General Programming
  3. C#
  4. Delete all rows from datagridview

Delete all rows from datagridview

Scheduled Pinned Locked Moved C#
questionannouncement
3 Posts 2 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.
  • N Offline
    N Offline
    NewToAspDotNet
    wrote on last edited by
    #1

    Hi all, I can delete the selected rows from datagridview by selecting the rows and pressing the del key: SqlCommandBuilder cb_imp = new SqlCommandBuilder(myda); myconn.Open(); myda.Update(mydt); Bud what's the way to delete all rows without selecting??? Thanx.

    C 1 Reply Last reply
    0
    • N NewToAspDotNet

      Hi all, I can delete the selected rows from datagridview by selecting the rows and pressing the del key: SqlCommandBuilder cb_imp = new SqlCommandBuilder(myda); myconn.Open(); myda.Update(mydt); Bud what's the way to delete all rows without selecting??? Thanx.

      C Offline
      C Offline
      C1AllenS
      wrote on last edited by
      #2

      Hello, Well if you do not want to select all rows and then delete, then you can implement that in Button Click or some menu selection. Use this code to delete all the rows. You will have to manually loop through the rows and delete them one by one. for (int i = this.dataGridView1.Rows.Count - 2; i > -1; i--) this.dataGridView1.Rows.RemoveAt(i); I hope this will help. Regards,

      Allen Smith ComponentOne LLC www.componentone.com

      N 1 Reply Last reply
      0
      • C C1AllenS

        Hello, Well if you do not want to select all rows and then delete, then you can implement that in Button Click or some menu selection. Use this code to delete all the rows. You will have to manually loop through the rows and delete them one by one. for (int i = this.dataGridView1.Rows.Count - 2; i > -1; i--) this.dataGridView1.Rows.RemoveAt(i); I hope this will help. Regards,

        Allen Smith ComponentOne LLC www.componentone.com

        N Offline
        N Offline
        NewToAspDotNet
        wrote on last edited by
        #3

        Hi Allen, This works well. thanx a lot

        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