highlighting rows in a DataGridView

L

lord.zoltar

I am wondering how you guys highlight cells or rows (by changing the
text or background colour) in a DataGridView. Right now, I apply styles
to certain rows or cells in the CellFormatting even handler, but the
way it works is by looping through all of the rows and then deciding if
that rows needs special formatting.
The problem is that I don't think this method will scale well. I have a
dataset with > 5,000 rows (and others are larger, this one is just a
test set) and I need a better way to apply styles to the cells. Is
there any way to apply styles to the rows or cells at the time they are
loaded (from the database) into the control, rather than when the
cellformatting handler is called?
or any better way to do it?
 
L

lord.zoltar

wikkiwikkiwaa said:
i think what you are looking for is the on DataBound event.

here is a good tutorial on custom formatting
http://www.asp.net/learn/dataaccess/tutorial11cs.aspx?tabid=63

and it comes available in a vb flavor also.

Hmm... I had a look at it, and it seems that the example only works
with the Web UI controls. It uses the GridView, I'm using the
DataGridView control. I haven't seen any events like the ones in the
GridView, but I don't think at this stage I could suddenly switch to
the GridView control.
To do custom highlighting on the DataGridView, it looks like I'll have
to override tha RowPrePaint handler to set the highlighting style. If
it's a success, I'll post the result here, unless anyone else has a
suggestion that's better than using the RowPrePaint handler?
 
L

lord.zoltar

Cor said:
"What foul is presenting 5000 rows in a
DataGridView to endusers?

What foul? An insistent client! :p ;)

Although, it's unlikely that more than 30 or 40 will ever be visible on
the screen at a time. Also, when I get the properly cleaned dataset
this particular query will probably not return more than 1000 rows.
However on our website is a solution for your question.
http://www.vb-tips.com/dbpages.aspx?ID=a426386e-6ecc-4126-a295-cf57ce269df2

I hope this helps,

Ahh, the CellFormatting handler! Yes, I had started off with that one
and it worked alright, but for some reason it gave me trouble,
depending on how I chose to format the cells in the table. I ended up
using RowPrePaint. It works nicely too. :)
 

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