473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Jul 21 '05 #1
4 1366
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" <no**@hotmail.com> wrote in message
news:58*********************@news.microsoft.com...
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

Jul 21 '05 #2
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

Jul 21 '05 #3
Jos

"SimonH" <no**@hotmail.com> wrote in message
news:58*********************@news.microsoft.com...
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(Cont ainer.DataItem,"myColorFie
ld")) %>'

Jos
Jul 21 '05 #4
> 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
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: SimonH | last post by:
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...
4
by: SimonH | last post by:
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...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
4
by: SimonH | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.