PC Review


Reply
Thread Tools Rate Thread

Background colour of column in datagrid

 
 
PJ
Guest
Posts: n/a
 
      2nd Mar 2004
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.
 
Reply With Quote
 
 
 
 
Jan Tielens
Guest
Posts: n/a
 
      2nd Mar 2004
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" <(E-Mail Removed)> schreef in bericht
news:58c001c40037$59e6dd80$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
DraguVaso
Guest
Posts: n/a
 
      2nd Mar 2004
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
you can find it there + a lot of other nice tips

Pieter

"PJ" <(E-Mail Removed)> wrote in message
news:58c001c40037$59e6dd80$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Guest
Posts: n/a
 
      2nd Mar 2004
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" <(E-Mail Removed)> wrote in message
>news:58c001c40037$59e6dd80$(E-Mail Removed)...
>> 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.

>
>
>.
>

 
Reply With Quote
 
DraguVaso
Guest
Posts: n/a
 
      2nd Mar 2004
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








<(E-Mail Removed)> wrote in message
news:556301c40049$f2441fe0$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> >news:58c001c40037$59e6dd80$(E-Mail Removed)...
> >> 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.

> >
> >
> >.
> >



 
Reply With Quote
 
Guest
Posts: n/a
 
      2nd Mar 2004
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 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
>
>
>
>
>
>
>
>
><(E-Mail Removed)> wrote in message
>news:556301c40049$f2441fe0$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> >news:58c001c40037$59e6dd80$(E-Mail Removed)...
>> >> 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.
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
BraveHeart
Guest
Posts: n/a
 
      3rd Mar 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
> you can find it there + a lot of other nice tips
>
> Pieter
>
> "PJ" <(E-Mail Removed)> wrote in message
> news:58c001c40037$59e6dd80$(E-Mail Removed)...
> > 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.

>
>



 
Reply With Quote
 
DraguVaso
Guest
Posts: n/a
 
      3rd Mar 2004
try this one:
http://www.syncfusion.com/FAQ/WinFor...44c.asp#q1075q

"BraveHeart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
> > you can find it there + a lot of other nice tips
> >
> > Pieter
> >
> > "PJ" <(E-Mail Removed)> wrote in message
> > news:58c001c40037$59e6dd80$(E-Mail Removed)...
> > > 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.

> >
> >

>
>



 
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
Background colour James Price at Premier Microsoft Outlook Calendar 1 14th Dec 2009 01:14 PM
Re: Background colour Diane Poremsky [MVP] Microsoft Outlook 0 20th Apr 2009 05:04 PM
change a cell background colour to my own RGB colour requirements =?Utf-8?B?U3RlcGhlbiBEb3VnaHR5?= Microsoft Excel Misc 4 16th Jun 2006 01:08 PM
DataGrid BackGround Color and Update dataGrid msp Microsoft Dot NET Compact Framework 3 27th Apr 2005 07:33 PM
Change datagrid column background color Barney Nicholls Microsoft C# .NET 6 21st Apr 2004 09:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 AM.