473,395 Members | 1,647 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,395 software developers and data experts.

Colors in datagrid

HI

In a previous versino of one of our apps we would store numeric values such
as 16777088 which we used to set the grid colors of a job on a TrueGrid grid
in VB6.
Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.

We have tried
NewTextBrush = DirectCast(Colour_Data(0).fcol.ToString,
System.Drawing.Brush)
but this returns a cast error
IS there a way of doing this?
Thanks in advance

Starbuck
Nov 21 '05 #1
4 1996

Starbuck wrote:
HI

In a previous versino of one of our apps we would store numeric values such as 16777088 which we used to set the grid colors of a job on a TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these integer values to System.Drawing.Brush values.

We have tried
NewTextBrush = DirectCast(Colour_Data(0).fcol.ToString,
System.Drawing.Brush)
but this returns a cast error


System.Drawing.Brush is an abstract class, so you must first decide
what concrete type of Brush you want. I'm guessing you want a
SolidBrush. The constructor for SolidBrush wants a Color, so let's go
look at that. We see that Color has a static (class) method called
FromArgb for making Color objects from numbers. Easiest to use is
FromArgb(Integer) where Integer is a complete 32-bit value. The top
byte is the alpha (transparency) value which you probably want as 255
(fully opaque) - the low three bytes are the RGB values you already
have. So we finally have:

Dim NewTextBrush as SolidBrush = _
New SolidBrush(Color.FromArgb(&Hff000000 + Colour_Data(0).fcol))

--
Larry Lard
Replies to group please

Nov 21 '05 #2
"Starbuck" <ke*@kevsbox.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
In a previous versino of one of our apps we would store numeric
values such as 16777088 which we used to set the grid colors of
a job on a TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these
integer values to System.Drawing.Brush values.


Create a new SolidBrush from the RGB components of your numeric
colour value. If you're /lucky/, you /might/ get away with ...

Dim z as New SolidBrush( Color.FromArgb( 16777088 ) )

.... but only if the "old" and "new" R, G and B components are in the
same order - I'm not sure they are. If not, you'll have to break your
numeric colour down into the three colour components and use

Dim c as Integer = 16777088
Dim R As Integer = (c And &HFF)
Dim G As Integer = (c And &HFF00) >> 8

Dim B as Integer = ( c And &HFF0000 ) >> 16

Dim z as New SolidBrush( Color.FromArgb( 0, R, G, B ) )

HTH,
Phill W.
Nov 21 '05 #3
"Starbuck" <ke*@kevsbox.com> schrieb:
In a previous versino of one of our apps we would store numeric values
such as 16777088 which we used to set the grid colors of a job on a
TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.


\\\
Dim b As New SolidBrush(ColorTranslator.FromOle(&H...))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Thanks for the tips guys.

Best Regards

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl...
"Starbuck" <ke*@kevsbox.com> schrieb:
In a previous versino of one of our apps we would store numeric values
such as 16777088 which we used to set the grid colors of a job on a
TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.


\\\
Dim b As New SolidBrush(ColorTranslator.FromOle(&H...))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

3
by: lasha | last post by:
hi all i have following problem, i want in my datagrid some rows to be red and some green, depends on volues of that row thanks
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
1
by: Richard | last post by:
All, In my Windows based .NET C# application I tried to change a form's background color to non-gray. The form backround color change had the desired ripple effect for most controls on the...
3
by: Amil Hanish | last post by:
Don't answer this if you don't know what you are talking about. I have lots of datagrids on many pages. I want to use a css stylesheet so color changes can be easily made via a single file. I...
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
3
by: Geoff Jones | last post by:
Hiya I'm hoping that somebody can help me with something that has been puzzling me today. I have a DataGrid. I can change the colors of various thing e.g. the Background color of the...
1
by: VMI | last post by:
Can the Windows datagrid in VS.Net '05 have rows of different colors? I'm trying to build an Outlook-style scheduler and I need to emulate the Calendar so that the rows change colors based on the...
0
by: WhiteWizard | last post by:
Here’s the situation: I am writing a C# Windows application using VS 2003. I have built a user control, and it has a Tab Control on it with (currently) 2 tab pages, and the whole thing sits...
3
by: =?Utf-8?B?QW5keQ==?= | last post by:
Hi, I'm trying to set the background color of a datagrid cell into a pastel color. I can change this into other colors in the grid_ItemDataBound event thus: e.Item.Cells(3).BackColor =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.