Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview who's source is a data table
once i clear the gridview using
dgvSolution.Columns.Clear();

and when a new data source is loaded into it, the contents are not shown unless i click on any one of the columns.
how do i resolve this?

This is how i reset its content and add new set of columns.
dt.Reset();
            numbersearch = num;
            DataColumn dc1 = new DataColumn("Number");
            DataColumn dc2 = new DataColumn("Correct");
            DataColumn dc3 = new DataColumn("Inline");
            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);
            dt.Columns.Add(dc3);

The code runs in a loop..The output is shown first time but hides after its reset.
Posted
Updated 2-Dec-11 0:06am
v5
Comments
D K N T H 2-Dec-11 4:10am    
what do you mean when you click on the view,, please provide your code.. thanks
Pramod Harithsa 2-Dec-11 4:12am    
when i click on one of the columns the data is shown, otherwise it stays hidden.
D K N T H 2-Dec-11 4:16am    
did you tried to rebind your gridview?
Pramod Harithsa 2-Dec-11 5:53am    
How do i re-bind in a WinForm application?
Pramod Harithsa 2-Dec-11 4:21am    
I use
dgvSolution.DataSource = da.generate();
the method returns a datatable. How do i bind grid view?

Do not clear the columns to clear the grid.
Set the datasource to null instead
dgvSolutions.DataSource=null;


To update your gridview,
make required changes / load a new DataTable and set it as the datasource

dgvSolution.AutoGenerateColumns = true;
dgvSolution.DataSource = dt;


If you do not wish columns to be auto-generated, then you must add columns manually & set each column's DataPropertyName to the DataTable's Field Name & then assign the source. (You can also add columns & set DataPropertyName in the designer)
 
Share this answer
 
Comments
Pramod Harithsa 2-Dec-11 5:13am    
Let me tell you what i actually want,
I display the score of a game in grid view. . once player starts the new game i want to clear the grid view.the whole code runs in a loop so i destroy the columns and crete new one's
try this.

C#
datagrid.databind();


thanks
 
Share this answer
 
Comments
Pramod Harithsa 2-Dec-11 7:02am    
In windows form such a method doesnt exist!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900