By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Background colour of column in datagrid

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.