PC Review


Reply
Thread Tools Rate Thread

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

 
 
SimonH
Guest
Posts: n/a
 
      11th Feb 2005
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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11th Feb 2005
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

"SimonH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
SimonH
Guest
Posts: n/a
 
      11th Feb 2005
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

 
Reply With Quote
 
Jos
Guest
Posts: n/a
 
      11th Feb 2005

"SimonH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      13th Feb 2005
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Font.Color to System.Drawing.Color in C# Andrew HUANG Microsoft Excel Programming 0 9th Jan 2008 07:01 PM
Binding a Drawing.Color value to a datagrid. Please help :-( SimonH Microsoft ASP .NET 4 13th Feb 2005 10:28 AM
Binding a Drawing.Color value to a datagrid. Please help :-( SimonH Microsoft Dot NET 4 13th Feb 2005 10:28 AM
threading, what different between DataGrid Binding to Binding TextBox mttc Microsoft Dot NET Framework Forms 3 19th Nov 2004 08:33 AM
How do I convert from a 'double' valued color to a System.Drawing.Color? Nat Microsoft Excel Programming 11 28th Jun 2004 01:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 AM.