Setting AutoGenerateColumns Property for DataGridView

I have a datagridview configured to auto-generate columns based on my class (using data binding).

It works fine for all my string type properties. However, I have a property of type enum using typeconverter to convert it to an image.

I would like my Grid column auto-generation to create a DataGridViewImageColumn instead of a DataGridViewTextBoxColumn .

The only DGV method that seems useful is columns. However, you cannot set the column there, just get and change.

Any ideas?

+4
source share
1 answer

as far as I know, AutoGeneration is not very customizable but you can make an alternative autogen for yourself:

set autogen = false, register for these events:

  • OnDataMemberChanged
  • OnDataSourceChanged

add one function that will be run for both, which will create columns for data dataSource:

  • header = column name
  • column type = according to what you want
  • data binding = column name
  • and etc.
+2
source

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


All Articles