DataGridView automatically generates columns

In my Windows form, I have a DataGridView component associated with a BindingSource. BindingSource is an object data source for an EntityFramework object.

The columns in my DataBridView are updated several times. Sometimes all properties are added as a column, but now it also deletes all my columns. Therefore, I lost all my settings.

When are columns automatically added?

(I am using VS.NET 2010)

Update:

// // Summary: // Gets or sets a value indicating whether columns are created automatically // when the System.Windows.Forms.DataGridView.DataSource or System.Windows.Forms.DataGridView.DataMember // properties are set. // // Returns: // true if the columns should be created automatically; otherwise, false. The // default is true. [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Advanced)] [DefaultValue(true)] public bool AutoGenerateColumns { get; set; } 

The property did not appear in the designer, and "hide additional properties" is not checked.

Update 2: When I update the entity frame model, all columns are added again. I can set the property in the form constructor. This is very annoying.

+6
source share
4 answers

I really don't know when this happens, but I try to create all the columns manually. I create the columns in the constructor and set the AutoGenerateColumns property to false in my code.

+4
source

Add this code or change the DataGridView AutoGenerateColumns to false

 DataGridView1.AutoGenerateColumns=false; 
+2
source

Try to leave the first of the automatically generated columns and set the visibility to false. If this does not help, try leaving them with Visible = false. Sorry for the bad english.

+1
source

Set the AutoGenerateColumns property to False, but remember how to do this before data binding. for example: DataGridView1.AutoGenerateColumns=false; DataGridView1.DataSource=getData(); DataGridView1.AutoGenerateColumns=false; DataGridView1.DataSource=getData();

The default value is True.

+1
source

Source: https://habr.com/ru/post/911079/


All Articles