How? Using a custom TypeConverter in custom grid column style.

L

Lee Gillie

I have bound a grid column to an enumeration data type.

I derive from DataGridTextBoxColumn and override GetColumnValueAtRow and
call a function I wrote to convert the enumeration value to a
descriptive text for display in the grid cell. This works well.

Even though the grid is not editable, and the column is readonly, when
one clicks on the cell I get a type conversion exception. Looking at the
stack I see Edit calls GetText which uses an "EnumConverter" to convert
the descriptive text to an int32, which ultimately tries to parse the
descriptive as an int32, and of course fails.

I see that DataGridTextBoxColumn has a PRIVATE type converter member.

I am seeking any pointers to examples, or samples, or explanations of
how to intercede the conversion of the descriptive back to an enumerated
value for my custom column type. I think I need to implement a type
converter, but I don't see how to tie it in. Or even just to know "it
can't be done" would be helpful.
 
D

Dmytro Lapshyn [MVP]

Hi Lee,

If your column is planned to be always read-only, the simplest solution
would be to override the Edit method and to provide an empty implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top