views:

86

answers:

3

I have a column in my DGV that is a custom type to display values of MyObjectType. My DataTable has the column created as MyObjectType, but the DGV creates a DataGridViewTextBox column and populates it with MyObjectType.ToString(); which is not the behavior I want.

Can I either force the data to be loaded into preexisting columns; or is there a away to specify that a MyObjectTypeColumn should be created to display MyObjectType data?

I need to display both an image and a text value for the MyObjectType value in a single column; similar to how the name column in explorer when using details view so I can't shoehorn the data into a single column like the default behavior.

A: 

Sounds like you may need to create a custom DataGridView Column.

http://www.code-magazine.com/article.aspx?quickid=0707061&page=1

http://msdn.microsoft.com/en-us/library/7fb61s43.aspx

David Glass
I have created it, but when I set a Datatable for a source it creates a text column for the MyObjectType and only shows its ToString value instead of creating a MyObjectTypeColumn.
Dan Neely
A: 

Setting the AutogenerateColumns property to false allowed me to use columns with types that I defined. Am I blind though, or is that property not exposed in the designer grid.

Dan Neely
It's not a part of the Properties that I can tell for the DataGridView. Not all Properties are exposed however.
0A0D
A: 

You have to set your DisplayMember and ValueMember if you are binding, I believe. I had a similar problem when binding to a ComboBox and I was just getting String[] array as well.

0A0D