469,593 Members | 1,931 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

DataGridView CellFormatting Event

How does "e.CellStyle" work?

When I do something like
if(e.ColumnIndex == 0 && e.RowIndex == 0)
DataGridView.Rows[0].DefaultCellStyle.BackColor = Color.Orange;

then the entire table goes orange; not just the 1st row. When I do
if(e.RowIndex == 0) e.CellStyle.BackColor = Color.Orange;

then 1st row goes orange only. Is it better to set the
"DefaultCellStyle" for a row in the "CellFormatting" event handler or
is that way of thinking wrong and just use "e.CellStyle".

I ask that because when I interate through the entire table in a load
event (not using CellFormating Event)
"DataGrideView[i,ii].DefaultCellStyle.BackColor = Color.Orange;" then
it takes about 25 seconds. Making "DataGridViewCellStyle cstyle = new
DataGridViewCellStyle(); cstyle.backcolor = color.orange;" with the
interation method brings it down to 3 seconds.

But for the "CellFormatting" event, using the "e.CellStyle.BackColor =
color.orange" takes about 3 seconds, and making a global "cstyle" and
doing "e.CellStyle = cstyle;" still takes 3 seconds. Does
CellFormating event automatically reuse a "DataGrideViewCellStyle"
object thus I don't have to do it myself. And is this resuing
property the reasion why my entire table goes orange when i do
"DataGridView.Rows[0].DefaultcellStyle.BackColor = Color.Orange;" for
the 1st cell, in the CellFormating event handler method?
:) Thanks Again again for your time. I've asked a lot of DataGridView
questions today already.

NB
Dec 31 '07 #1
0 3835

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David | last post: by
3 posts views Thread by David Veeneman | last post: by
3 posts views Thread by Prashwee | last post: by
2 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by
4 posts views Thread by NvrBst | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.