Changing color in Datagrid Cell

J

jasmine

I was wondering if it's possible to change the backcolor
of certain rows in a datagrid??

Thanks alot!
 
R

Romain TAILLANDIER

the DataGrid.AlternatingBackColor Property may be all you need ...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsdatagridclassalternatingbackcolortopic.asp

You have this pages to visit :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskformattingthedatagridatdesigntime.asp
and all 6 or 7 sub articles ...

then the class DataGridColumnStyle
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskformattingthedatagridatdesigntime.asp



hopes that's help
ROM
 
G

Guest

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
 
J

jasmine

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.
 
R

Romain TAILLANDIER

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
 
L

Lloyd Dupont

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.
 
Z

Zanna

Romain TAILLANDIER said:
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
 
A

Alex Feinman [MVP]

This is a compact framework newsgroup and information from the full
framework docs is not exactly relevant most of the time. Such as this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top