DataGridView AutoGenerateColumns getting reset to true

0
0

Hi guys,

Something I noticed today, version 3.5.4. I had a DataGridView and had set its AutoGenerateColumns property to false in the designer. I publish my application and saw that after the columns I had explictly created, there was the list af all the datasource properties. Went to the designer and saw that AutoGenerateColumns was true. I thought, what the hell, I must have been mistaken. I changed it to false and rebuilt the project. And ther, in front of my eyes, as the built finished the designer flashed and the AutoGenerateColumns was changed to true.

The workaround is to set it to false in code, in the constructor or OnLoad, but still, fix it.

Best,
Alex

 

 

  • You must to post comments
0
0

I had a similar issue, when the designer started to forcefully insert AutoGenerateColumns = true into all the DGVs.

The reason seemed to be that I had this property in my DataGridViewExt middle-class.

        [DefaultValue(false)]
[Browsable(true)]
public new bool AutoGenerateColumns {
set => base.AutoGenerateColumns = value;
get => base.AutoGenerateColumns;
}

All I needed is to remove this overload from the middle-class, and the designer seems to be OK now.

  • You must to post comments
0
0

Hi Alex,

This is the correct behavior.

AutoGenerateColumns is not shown in the property grid because it’s managed by the grid editor, and altering InitializeComponent() doesn’t mean the changes are preserved.

When a DataSource is assigned at design time the property AutoGenerateColumns is set to false after the columns are autogenerated. When DataSource is reset the property is reset to true (default) as well. It can be set to the desired value in code.

Best regards,
Alaa

//

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.