Datagridview Invalidate


M

Mike Nicol

Hi all

I'm sure this is just something I'm doing wrong, but not too sure.

I have a form with a DataGridView control. The DataGridView (DGV) has
VirtualMode = True.

As a private member of the form, I have an array of booleans. The first
column of the DGV is a DataGridViewCheckBoxColumn.

So far, no problems. I've implemented the CellValueNeeded and
CellValuePushed functions, and all is A-OK. The user can happily click on
the different checkboxes, and I get the value changes in my array. (at this
point, I'd like to say... the DataGridView in VirtualMode RAWKS!!! .. nice
one MS).

I've implemented an Event Handler to handle the ColumnHeaderMouseClick
event. I want the user to be able to click the header of the column to
toggle the entire column values off or on. A "Select All" / "Unselect all"
function.

This works, except if a cell in the column, being toggled, is selected. The
DGV does not seem to fire the CellValueNeeded function for the selected
cell.

I've included a DGV.InvalidateColumn(e.columnindex) at the end of the
ColumnHeaderMouseClick event handler, to force it to redraw the column, but
alas, the cell is still not being refreshed. If I select a different cell,
the old cell is refresh (as expected).

I've fixed this problem by changing the focus at the start of the event
handler to one of the labels on the form. TA DA, this works.

I don't like crumby code like that, and was hoping someone could tell me
what I'm doing wrong.

I've tried to DGV.ClearSelection() at the beginning of the event handler,
still no luck. I've tried DGV.CancelEdit(), no luck.

Any ideas?
 
Ad

Advertisements

M

Mike Nicol

A little more information.

It seems that the DGV.CellValueNeeded DOES fire for the selected Cell, and
the correct value is being set to e.Value. But the screen redraw is not
updating the cell display. Mmm.... the thick plottens.

Oh and BTW, I don't mind getting responses soon, it's ok, let your inner
poster loose...
 
Ad

Advertisements

M

Mike Nicol

It seems that because the cell is selected / current... it doesn't get
redrawn until the user goes off the cell.

Well... I've found a way to Deselect any cell in the DGV.

DGV.CurrentCell = null;

That works
 

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

Similar Threads

DataGridView Invalidate Cell reply 0
Datagridview 3
DataGridView 0
datagridview 1
DataGridView 4
DataGridView GotFocus 1
datagridview help 1
DataGridView "HideSelection" 1

Top