Binding a Drawing.Color value to a datagrid. Please help :-(

S

SimonH

Hi everyone,

If anyone can help me with this I would be really really greatful.

I have a custom object that I can't change. Two of the properties (hair colour
and eye colour) are of type Drawing.Color

Unfortunately I cant change the class implementation to make these properties
more friendly.

My question is, given that I can't bind a colour to the datagrid (the bind
process just ignores those two properties) what is the best way to have something
sensible displayed?

I don't know whether to use some sort of wrapper or something and I can't
override the property

Essentially my question boils down to this:

I have to display something sensible corresponding to the color type that
has been provided.
I then need to allow the user to change that value and then somehow convert
what the user enters back into a Drawing.Color.

I've never come accross someone who's used a Color in this way before. Should
he/she not have just used a string or perhaps at least an enummeration.

Thank you all

Simon
 
E

Eliyahu Goldin

Simon,

You don't have to databind in one expression. Just make ItemDataBound event
handler. In the handler check color and set grid cell values in whatever you
wish.

Eliyahu
 
S

SimonH

Hello Eliyahu,

Thanks for your reply.

I'm still not sure how I can use the itemdataboundevent to put data in. The
documentation says that at this point the data has already been given to
the control.

Are you saying that some if statements in the handler could allow me to identify
the color and then output the colour as text? The other things is, I'd like
to be able to output the colours as a dropdown

Thanks for your help

Simon
 
J

Jos

SimonH said:
Hi everyone,

If anyone can help me with this I would be really really greatful.

I have a custom object that I can't change. Two of the properties (hair colour
and eye colour) are of type Drawing.Color

Unfortunately I cant change the class implementation to make these properties
more friendly.

My question is, given that I can't bind a colour to the datagrid (the bind
process just ignores those two properties) what is the best way to have something
sensible displayed?

I don't know whether to use some sort of wrapper or something and I can't
override the property

Essentially my question boils down to this:

I have to display something sensible corresponding to the color type that
has been provided.
I then need to allow the user to change that value and then somehow convert
what the user enters back into a Drawing.Color.

I've never come accross someone who's used a Color in this way before. Should
he/she not have just used a string or perhaps at least an enummeration.

Try this databinding expression to convert the database text field to a
color:

myColorProperty='<%#
System.Drawing.Color.FromName(DataBinder.Eval(Container.DataItem,"myColorFie
ld")) %>'

Jos
 
E

Eliyahu Goldin

I'm still not sure how I can use the itemdataboundevent to put data in.
The
documentation says that at this point the data has already been given to
the control.
Exactly. Therefore you can safely get/set data values from/to the control
properties, noone else will overwrite them.
Are you saying that some if statements in the handler could allow me to identify
the color and then output the colour as text? Yes.

The other things is, I'd like
to be able to output the colours as a dropdown
For this you need a template column with a dropdown list control and to
populate the control in the same ItemDataBound event.

Eliyahu
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top