greggorob64
greggorob64

Reputation: 2557

Configuring 'AutoGenerateColumns' property of a DataGridView

I have a datagridview configured to autogenerate columns based on my class (using databinding).

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

I'd like for my Grid's autogeneration of columns to produce a DataGridViewImageColumn instead of a DataGridViewTextBoxColumn.

The only DGV method that seems helpful is columns added. However, you cannot set the column there, only get & modify.

Any Ideas?

Upvotes: 4

Views: 995

Answers (1)

Amitbe
Amitbe

Reputation: 401

as far as i know, the AutoGeneration isn't very configurable but you can make an alternative auto gen for yourself:

set autogen = false, register to these events:

  • OnDataMemberChanged
  • OnDataSourceChanged

add a single function that will be triggered for both, which will create columns for the dataSource given:

  • header = column name
  • column type = according to what you want
  • data binding = the column name
  • etc.

Upvotes: 2

Related Questions