How to control Column Type in DataGridView that is bound to a CustomObject?

后端 未结 2 1522
小蘑菇
小蘑菇 2021-01-15 12:28

I have a DataGridView in a C# WinForms app that is DataBound at runtime (through Form_Load) to a custom Object.
In the design view of the DataGridView I have no columns

相关标签:
2条回答
  • 2021-01-15 13:06

    The default columns are based on the data-type. I haven't checked, but for a link you could try exposing the data as Uri, but that might be hopeful. Really, if you want a specific type of column - add the columns through code and set DataGridView.AutoGenerateColumns to false.

    As Andrew implies; normally something like reflection is used to generate the columns, and you'll get a column for every (browsable + public + readable) property. There is a layer of abstraction on top of this if you need, but this won't help with adding a hyperlink column.

    0 讨论(0)
  • 2021-01-15 13:15

    You can pre-create your columns in the designer. If the name of the column matches the name of the property the column will end up bound to, the databinding will take care of the DGV population for you as before.

    0 讨论(0)
提交回复
热议问题