Datagridview columns keep appearing

  • Thread starter Thread starter Brooke
  • Start date Start date
B

Brooke

I have a form with a datagridview and I set the columns that I want on the
grid. Whenever I close the form in the form designer and then open it back
up, it will pull in all of the columns from the binding source. I have to
manually edit the columns every time and remove all of the unwanted ones.
What is going on?
 
I am not sure but it sounds to me like the values from your datasource are
being grabed at design time and are then being serialized into your
designer.cs file.

When user controls are displayed at design time, visual studio is creating
instances of those controls. If you are loading data durring construction of
the control the designer will see those values and serialize them into the
code DOM (Dont quote me on this, it is just what I have observed).

To see if this is happening just open up your design.cs file and see if the
data is being included in your code. If this is what is going on try moving
the code that is creating the databinding into an if statement that checks
the this.DesignMode variable.

if(!this.DesignMode){
// do databinding here.
}


Jeremy Shovan
http://www.jeremyshovan.com
 
I checked the code and it has the following

this.dataGridViewLookup.AutoGenerateColumns = false;



this.dataGridViewLookup.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {

this.reviewID,

this.projectID,

this.drawingID,

this.reviewDescription});



Cannot find the problem...
 
Brook,

Are the columns reviewID, projectID, drawingID, reviewDescription the
columns that you expected to see or are they being added automatically be
the designer?



Brooke said:
I checked the code and it has the following

this.dataGridViewLookup.AutoGenerateColumns = false;



this.dataGridViewLookup.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {

this.reviewID,

this.projectID,

this.drawingID,

this.reviewDescription});



Cannot find the problem...

Jeremy Shovan said:
I am not sure but it sounds to me like the values from your datasource are
being grabed at design time and are then being serialized into your
designer.cs file.

When user controls are displayed at design time, visual studio is
creating instances of those controls. If you are loading data durring
construction of the control the designer will see those values and
serialize them into the code DOM (Dont quote me on this, it is just what
I have observed).

To see if this is happening just open up your design.cs file and see if
the data is being included in your code. If this is what is going on try
moving the code that is creating the databinding into an if statement
that checks the this.DesignMode variable.

if(!this.DesignMode){
// do databinding here.
}


Jeremy Shovan
http://www.jeremyshovan.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top