DataGridView CellFormatting Event

N

NvrBst

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
 
G

Greg

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

Here is a must read for performance gaines using the DataGridView
control.
This document is a good resource for "how to" when programming the DGV
control.
http://windowsclient.net/samples//Go To Market/DataGridView/DataGridView FAQ.doc


Greg
 
N

NvrBst

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.

Here is a must read for performance gaines using the DataGridView
control.
This document is a good resource for "how to" when programming the DGV
control.http://windowsclient.net/samples//Go To Market/DataGridView/DataG...

Greg- Hide quoted text -

- Show quoted text -

Thank you kindly :) I shall read it this week.

NB
 

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