Windows Forms DataGrid View Clearing Problem
-
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
-
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
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?
-
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?
-
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
Isn't there a Rows collection that you can clear? AFAIK, it shouldn't change the column headers...
-
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
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
-
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
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.
-
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.
-
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")
-
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")
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