DataGridView Cannot clear this list.
  • hi i want to clear my datagridview rows and using code


    dg.Rows.Clear();


    but it give exception
    Cannot clear this list.
  • 1 Comment sorted by
  • Vote Up0Vote Down ithackerithacker
    117.50 Karma Accepted Answer
    Hi i think you filling grid through .DataSource Property so you have to use below code for clear rows.


     if (dg.DataSource != null)
                {
                    dg.DataSource = null;
                }
                else
                {
                    dg.Rows.Clear();
                }


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative