Painting DataGrid Column Headers in WinForms (C#)

J

John Smith

I've posted this to the WinForms forum at GotDotNet - but thought I'd also
try my luck in the WinForms NG.

Yet another DataGrid post, I'm sure... :) But Googling the Web far and wide
has not yielded any results, and my own investigations into the
DataGrid-related classes in the Framework have been even less fruitful. So
the question is really simple (the application is less so, and I'll pose the
question for that as well, in a bit): how do I custom paint into a
DataGrid's column header area? Ideally, I'd like to do this in a derived
DataGridColumnStyle, so that I can do this for any arbitrary column and make
it part of the column's style.

The real reason I am asking is because I am trying to develop my own custom
column style for a DataGrid in which I have a column of checkboxes (much
like DataGridBoolColumn) and also a checkbox in the column header. The
functionality I'm trying to implement is to allow each row's checkbox to be
used to select/deselect the row. The checkbox in the column header, then,
would be used as a "Select All" checkbox. If there's a better place to
Show() my "Select All" checkbox (as opposed to putting it in a Paint()
method), I'm definitely all ears! (all eyes?) I think I've figured out how
to trap the event for each row to actually cause selection of the row, but I
still need to get the "Select All" to work.

I know I'm not the most familiar with the WinForms DataGrid (I only recently
figured out the "right" way to do a data-bound DataGridComboBox column,
which once I spruce up, I'll consider for posting here), but this seems to
be a simple extension that I have as yet to figure out how to approach as
far as the implementation goes.

Any thoughts/ideas/suggestions on how to do both of the above? Am I being
really naive here, or is this actually harder than it sounds (as I've
believed all along)?
 

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