How do I manage the column type in the DataGridView associated with a CustomObject?

I have a DataGridView in a C # WinForms application that is a Runtime DataBound (via Form_Load) for a custom object.
In the Design View of the DataGridView, I have no columns configured.
When the Form loads the columns, they are automatically created from the data in the custom object that the DataBound belongs to.
My question is how can I manage the auto-generated columns. For example, if I want one of the columns to be a DataGridViewLinkColumn instead of the DataGridViewTextBoxColumn that is automatically generated?

+2


source to share


2 answers


By default, columns are based on data type. I have not tested, but for reference, you can try to expose the data as Uri

, but that might be reassuring.
Indeed, if you need a specific type of column - add columns via code and set DataGridView.AutoGenerateColumns

to false

.



As Andrew suggests; usually something like reflection is used to create columns and you will get a column for each (viewable + public + readable) property. There is an abstraction layer if you need to, but that won't help you add a hyperlink column.

+3


source


You can pre-create your columns in the designer. If the column name is the same as the property name that the column collided with, data binding will take care of you as before, the DGV population.



+1


source







All Articles