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. Windows Forms DataGrid View Clearing Problem

Windows Forms DataGrid View Clearing Problem

Scheduled Pinned Locked Moved C#
helpcsswinformsquestion
9 Posts 5 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.
  • D Offline
    D Offline
    deepaks3
    wrote on last edited by
    #1

    Hi, I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there. Thanks.

    Deepak Surana

    C D B 3 Replies Last reply
    0
    • D deepaks3

      Hi, I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there. Thanks.

      Deepak Surana

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

      deepaks3 wrote:

      I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there.

      :confused: Clearing a row would surely clear columns too? Can you give an example of what the result you are looking for?

      D 1 Reply Last reply
      0
      • C ChandraRam

        deepaks3 wrote:

        I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there.

        :confused: Clearing a row would surely clear columns too? Can you give an example of what the result you are looking for?

        D Offline
        D Offline
        deepaks3
        wrote on last edited by
        #3

        Ok, There are cerain no of rows in the grid, so when i click on the clear button i want that only the column names should be visible but not any rows. And i have aded the columns on the design time, so i want to retain those columns.

        Deepak Surana

        C 1 Reply Last reply
        0
        • D deepaks3

          Ok, There are cerain no of rows in the grid, so when i click on the clear button i want that only the column names should be visible but not any rows. And i have aded the columns on the design time, so i want to retain those columns.

          Deepak Surana

          C Offline
          C Offline
          ChandraRam
          wrote on last edited by
          #4

          Isn't there a Rows collection that you can clear? AFAIK, it shouldn't change the column headers...

          1 Reply Last reply
          0
          • D deepaks3

            Hi, I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there. Thanks.

            Deepak Surana

            D Offline
            D Offline
            dipak dipak
            wrote on last edited by
            #5

            You may clear the value in loop using row index and column index; for example: setting null to Row index 0, Column index 0 dgvItemList.Rows[0].Cells[0].Value = ""; I think, u got it. Best of Luck.

            Dipak

            1 Reply Last reply
            0
            • D deepaks3

              Hi, I am using a DataGrid View on my windows forms. I want to clear all the rows of the grid on certain event, for that i tried to set the data source property to null. But it also cleared the columns. I also tried to use the clear function of the rows ut it was of no help; How can i just clear teh rows and let the columns be intact in there. Thanks.

              Deepak Surana

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #6

              dataGridView1.Rows.Clear();

              My head asplode!

              Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.

              D 1 Reply Last reply
              0
              • B Brady Kelly

                dataGridView1.Rows.Clear();

                My head asplode!

                Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.

                D Offline
                D Offline
                deepaks3
                wrote on last edited by
                #7

                Rows.Clear() isnt working..

                Deepak Surana

                J 1 Reply Last reply
                0
                • D deepaks3

                  Rows.Clear() isnt working..

                  Deepak Surana

                  J Offline
                  J Offline
                  Justin Perez
                  wrote on last edited by
                  #8

                  Instead of trying to clear the rows on the dataGridView, try clearing the rows on it's data source. lets sat the source of the datagridView is in a DataSet. Lets just make this one up: this.YourDataSet.YourDataTable. Clear the rows from the DataTable, and the DataGridView will see the changes in the DataTable and reflect the cleared rows. Try this: this.YourDataSet.YourDataTable.Clear();

                  "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

                  D 1 Reply Last reply
                  0
                  • J Justin Perez

                    Instead of trying to clear the rows on the dataGridView, try clearing the rows on it's data source. lets sat the source of the datagridView is in a DataSet. Lets just make this one up: this.YourDataSet.YourDataTable. Clear the rows from the DataTable, and the DataGridView will see the changes in the DataTable and reflect the cleared rows. Try this: this.YourDataSet.YourDataTable.Clear();

                    "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

                    D Offline
                    D Offline
                    deepaks3
                    wrote on last edited by
                    #9

                    Actually its very simple... grid.datasource = null; grid.rows.clear(); grid.refresh(); and a Indian Programmer gave me the solution by the way.... so if an Indian asked a programming question in the forest .... it will be Urgent.. and i think only Indians can solve it.. no others.. ;P :laugh:

                    Deepak Surana

                    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