PC Review


Reply
Thread Tools Rate Thread

Changing color in Datagrid Cell

 
 
jasmine
Guest
Posts: n/a
 
      4th Mar 2004
I was wondering if it's possible to change the backcolor
of certain rows in a datagrid??

Thanks alot!
 
Reply With Quote
 
 
 
 
Romain TAILLANDIER
Guest
Posts: n/a
 
      4th Mar 2004
the DataGrid.AlternatingBackColor Property may be all you need ...
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformsdatagridclassalternatingbackcolortopic.asp

You have this pages to visit :
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbtskformattingthedatagridatdesigntime.asp
and all 6 or 7 sub articles ...

then the class DataGridColumnStyle
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbtskformattingthedatagridatdesigntime.asp



hopes that's help
ROM


"jasmine" <(E-Mail Removed)> a écrit dans le message de
news: 6e2c01c401bf$5ce8d2c0$(E-Mail Removed)...
> I was wondering if it's possible to change the backcolor
> of certain rows in a datagrid??
>
> Thanks alot!



 
Reply With Quote
 
Zanna
Guest
Posts: n/a
 
      4th Mar 2004
Romain TAILLANDIER wrote:

> the DataGrid.AlternatingBackColor Property may be all you need ...
> http://msdn.microsoft.com/library/de...us/cpref/html/
> frlrfsystemwindowsformsdatagridclassalternatingbackcolortopic.asp


And there is no way to color an arbitrary row, or even a cell?

Thanks

 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      4th Mar 2004
Check out Alex Feinman's DataGridEvenOdd sample here:-
http://www.alexfeinman.com/samples.asp

You can possibly adapt this to operate on an individual row (not sure about
individual cell level)

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Zanna" <(E-Mail Removed)> wrote in message
news:c273qq$1osv74$(E-Mail Removed)...
> Romain TAILLANDIER wrote:
>
> > the DataGrid.AlternatingBackColor Property may be all you need ...
> >

http://msdn.microsoft.com/library/de...us/cpref/html/
> > frlrfsystemwindowsformsdatagridclassalternatingbackcolortopic.asp

>
> And there is no way to color an arbitrary row, or even a cell?
>
> Thanks
>



 
Reply With Quote
 
=?Utf-8?B?c2tpY293?=
Guest
Posts: n/a
 
      4th Mar 2004
I was able to alter Alex's great handler to colour individual rows.

I created an array of Boolean who's size is equal to the number of rows in the Datagrid, and then I check that array within the ForceRepaintGridRows/ForceRepaintGridRow methods to see if a row should be coloured or not (True paint and False don't paint)

The handler could also be altered to paint rows depending on the contents of a particular cell in a row as well

I'm sure that you could alter the handler even farther to paint individual cells as well by altering the _GetRowBounds rectangle to being the size of the cell to be painted

Good luck
skico


 
Reply With Quote
 
jasmine
Guest
Posts: n/a
 
      5th Mar 2004
After looking throu Alex's great sample code, I was still
very confused since I have no experience in C# before.
Does anyone happen to have any DataGrid sample code in
VB.NET??? I really appreciated!!

Thank you sooo much!!!


>-----Original Message-----
>I was able to alter Alex's great handler to colour

individual rows.
>
>I created an array of Boolean who's size is equal to the

number of rows in the Datagrid, and then I check that
array within the ForceRepaintGridRows/ForceRepaintGridRow
methods to see if a row should be coloured or not (True
paint and False don't paint).
>
>The handler could also be altered to paint rows depending

on the contents of a particular cell in a row as well.
>
>I'm sure that you could alter the handler even farther to

paint individual cells as well by altering the
_GetRowBounds rectangle to being the size of the cell to
be painted.
>
>Good luck,
>skicow
>
>
>.
>

 
Reply With Quote
 
Romain TAILLANDIER
Guest
Posts: n/a
 
      5th Mar 2004
there is a thread on microsoft.public.dotnet.framework
may be interest you. I quote

<quote>
1) Individual cells can be formatted differently by deriving you own
DatGridColumnStyle and overriding the OnPaint method. Lookup the
DataGridTextBoxColumn.Paint Method.

2) Through the DataView associated with the grid you can lock updates.

3) Handling the CurrentCellChanged event you cna stop a cell from getting
the foucs, ie move to the next cell or row.

Regards
Michael
</quote>

ROM


"Peter Foot [MVP]" <(E-Mail Removed)> a écrit dans le message
de news: uBQzQ$(E-Mail Removed)...
> Check out Alex Feinman's DataGridEvenOdd sample here:-
> http://www.alexfeinman.com/samples.asp
>
> You can possibly adapt this to operate on an individual row (not sure

about
> individual cell level)
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Zanna" <(E-Mail Removed)> wrote in message
> news:c273qq$1osv74$(E-Mail Removed)...
> > Romain TAILLANDIER wrote:
> >
> > > the DataGrid.AlternatingBackColor Property may be all you need ...
> > >

>

http://msdn.microsoft.com/library/de...us/cpref/html/
> > > frlrfsystemwindowsformsdatagridclassalternatingbackcolortopic.asp

> >
> > And there is no way to color an arbitrary row, or even a cell?
> >
> > Thanks
> >

>
>



 
Reply With Quote
 
Lloyd Dupont
Guest
Posts: n/a
 
      5th Mar 2004
BTW there is an OpenSource DataGrid contol found here in the OpenSource
section
http://www.ihook.cc

I did some debugging today (thanks to Alex Ayakin's ApplicationEx code) and
solve all scrolling&repaint problem and should make a new version in a
couple of days (once the change would have been tested thoroughly enough)

It's very much in the Java' JTable spirit and you have complete control on
the display of any single cell.

"jasmine" <(E-Mail Removed)> a écrit dans le message de
news:6e2c01c401bf$5ce8d2c0$(E-Mail Removed)...
> I was wondering if it's possible to change the backcolor
> of certain rows in a datagrid??
>
> Thanks alot!



 
Reply With Quote
 
=?Utf-8?B?c2tpY293?=
Guest
Posts: n/a
 
      5th Mar 2004
jasmine

You can convert the C# code to VB code here

http://authors.aspalliance.com/aldot.../translate.asp


 
Reply With Quote
 
Zanna
Guest
Posts: n/a
 
      5th Mar 2004
"Romain TAILLANDIER" <(E-Mail Removed)> wrote in message

> 1) Individual cells can be formatted differently by deriving you own
> DatGridColumnStyle and overriding the OnPaint method. Lookup the
> DataGridTextBoxColumn.Paint Method.


I don't see any DatGridColumnStyle.Paint nor DataGridTextBoxColumn.Paint
Method.

Are you sure you are talking about CF?

Bye


 
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
Changing cell color in datagrid kanepart2@hotmail.com Microsoft VB .NET 1 1st Aug 2007 07:00 PM
changing the color of a cell in a datagrid Franck Microsoft ASP .NET 7 12th Oct 2005 07:53 AM
changing bg color of individual datagrid cell Mad Scientist Jr Microsoft Dot NET Framework Forms 1 24th Nov 2004 09:21 PM
changing bg color of individual datagrid cell Mad Scientist Jr Microsoft VB .NET 3 23rd Nov 2004 10:37 PM
Datagrid: changing cell color JR Microsoft ADO .NET 2 21st Sep 2003 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 PM.