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

Background colour of column in datagrid

PJ
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level
for all columns.
Nov 20 '05 #1
7 2741
You can use the free open-source grid: ExtendedDataGrid:
http://dotnet.leadit.be/extendeddatagrid/

It has a formatted textbox column which you can use to color individual
cells.

--
Greetz,
Jan
________________________
Read my weblog: http://weblogs.asp.net/jan

"PJ" <pa*@noblenet.co.uk> schreef in bericht
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level
for all columns.

Nov 20 '05 #2
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <pa*@noblenet.co.uk> wrote in message
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level
for all columns.

Nov 20 '05 #3
This was helpful, thanks. But to add to the question, I
want to be able to set different colors for the column
header cells also and I don't think the tips cover this.
Any ideas?
-----Original Message-----
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <pa*@noblenet.co.uk> wrote in message
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level for all columns.

.

Nov 20 '05 #4
Hm, I didn't find this. Although I guess it must be possible by using the
Paint-event of the DataGrid.
I used this function to write something to some row-headers. I guess the
same must be possible with the column-headers:
Private Sub dbgFolder_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles dbgFolder.Paint

Dim row As Integer

row = TopRow()

Dim yDelta As Integer

If row >= 0 Then

yDelta = (dbgFolder.GetCellBounds(row, 0).Height + 1)

Dim y As Integer

y = (dbgFolder.GetCellBounds(row, 0).Top + 2)

Dim cm As CurrencyManager

cm = CType(Me.BindingContext(dbgFolder.DataSource,
dbgFolder.DataMember), CurrencyManager)

Dim dtvGrid As DataView

dtvGrid = New DataView(dtblGrid)

'5 omdat em anders de onderste telkens ni tekende...

Do While ((y < (dbgFolder.Height - yDelta + 3)) AndAlso (row <
cm.Count))

'get & draw the header text...

If DateDiff(DateInterval.Hour,
dtvGrid.Item(row).Item("DateFile"), Now) <= 12 Then

Dim text1 As String

' text1 = System.String.Format("row{0}", row)

text1 = System.String.Format("N", row)

e.Graphics.DrawString(text1, dbgFolder.Font, New
SolidBrush(Color.Black), 4, y)

End If

y = (y + yDelta)

row = (row + 1)

Loop

End If

End Sub

Or maybe override the Paint-event of the cell (I guess that's better, hehe),
and than use

g.FillRectangle(e.BackBrush, bounds)

But to be hon,nest I'm not really an expert of these things. I did some
stuff in it to extend the datagrid, but that's all :-)

Hope this helps,

Pieter


<an*******@discussions.microsoft.com> wrote in message
news:55****************************@phx.gbl...
This was helpful, thanks. But to add to the question, I
want to be able to set different colors for the column
header cells also and I don't think the tips cover this.
Any ideas?
-----Original Message-----
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <pa*@noblenet.co.uk> wrote in message
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level for all columns.

.

Nov 20 '05 #5
Yes, it helped thanks. I am just a little surprised at
the coding necessary just to alter the background color
of a column header. This really should be a property of
the DataGridColumnStyle class.

-----Original Message-----
Hm, I didn't find this. Although I guess it must be possible by using thePaint-event of the DataGrid.
I used this function to write something to some row- headers. I guess thesame must be possible with the column-headers:
Private Sub dbgFolder_Paint(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.PaintEventArgs) Handles dbgFolder.Paint
Dim row As Integer

row = TopRow()

Dim yDelta As Integer

If row >= 0 Then

yDelta = (dbgFolder.GetCellBounds(row, 0).Height + 1)
Dim y As Integer

y = (dbgFolder.GetCellBounds(row, 0).Top + 2)

Dim cm As CurrencyManager

cm = CType(Me.BindingContext (dbgFolder.DataSource,dbgFolder.DataMember), CurrencyManager)

Dim dtvGrid As DataView

dtvGrid = New DataView(dtblGrid)

'5 omdat em anders de onderste telkens ni tekende...
Do While ((y < (dbgFolder.Height - yDelta + 3)) AndAlso (row <cm.Count))

'get & draw the header text...

If DateDiff(DateInterval.Hour,
dtvGrid.Item(row).Item("DateFile"), Now) <= 12 Then

Dim text1 As String

' text1 = System.String.Format("row{0}", row)
text1 = System.String.Format("N", row)

e.Graphics.DrawString(text1, dbgFolder.Font, NewSolidBrush(Color.Black), 4, y)

End If

y = (y + yDelta)

row = (row + 1)

Loop

End If

End Sub

Or maybe override the Paint-event of the cell (I guess that's better, hehe),and than use

g.FillRectangle(e.BackBrush, bounds)

But to be hon,nest I'm not really an expert of these things. I did somestuff in it to extend the datagrid, but that's all :-)

Hope this helps,

Pieter


<an*******@discussions.microsoft.com> wrote in message
news:55****************************@phx.gbl...
This was helpful, thanks. But to add to the question, I
want to be able to set different colors for the column
header cells also and I don't think the tips cover this. Any ideas?
>-----Original Message-----
>http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
>you can find it there + a lot of other nice tips
>
>Pieter
>
>"PJ" <pa*@noblenet.co.uk> wrote in message
>news:58****************************@phx.gbl...
>> How can you set the background color of individual
>> columns in a datagrid to be different to others? The
>> table styles only allow you to do this at the grid

level
>> for all columns.
>
>
>.
>

.

Nov 20 '05 #6
It is very good but how can I autosize the rowheights in my datagrid by
VB.NET (not C# , I can't convert C# to VB.NET on this page)?

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <pa*@noblenet.co.uk> wrote in message
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level
for all columns.


Nov 20 '05 #7
try this one:
http://www.syncfusion.com/FAQ/WinFor...44c.asp#q1075q

"BraveHeart" <ho*******@yahoo.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
It is very good but how can I autosize the rowheights in my datagrid by
VB.NET (not C# , I can't convert C# to VB.NET on this page)?

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <pa*@noblenet.co.uk> wrote in message
news:58****************************@phx.gbl...
How can you set the background color of individual
columns in a datagrid to be different to others? The
table styles only allow you to do this at the grid level
for all columns.



Nov 20 '05 #8

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

Similar topics

0
by: ZaGras | last post by:
does anybody know make the column in the datagrid with different background colour, meaning that column1 is blue in colour, column2 is yellow in colour..?
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
14
by: John Doe | last post by:
Hi Is it possible to set the background colour of a grid based on a value in data? I guess that it is simple but I have been unable to figure it out. TIA
1
by: Michael Turner | last post by:
Anyone know if you can add a background image to a datagrid, there is a property for colour but not for an image.
0
by: satish | last post by:
I have a table with two columns field1 int,Field2 and added a column to datagrid on runtime sum (field1+field2) ,upon changing the data in either of the fileds the sum field or column too changes ....
1
by: satish | last post by:
I have a table with two columns field1 int,Field2 and added a column to datagrid on runtime sum (field1+field2) ,upon changing the data in either of the fileds the sum field or column too changes ....
3
Frinavale
by: Frinavale | last post by:
Hi there, I'm using JavaScript to highlight a row or column in a table. I have created a CSS class that changes the background colour to a light blue and I apply this class to the cells in the...
2
by: vinpkl | last post by:
hi all i have two column div structure in which i have applied black background colour to the main div which holds the two columns (left and right divs). In internet explorer 7 the structure...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.