DGV Virtual Mode and CellValueNeeded

ufoq

New member
Joined
Oct 4, 2006
Messages
3
Programming Experience
Beginner
I have a very strange problem...

My Datagridview is in Virtual Mode. 2 of the columns are data-bound, and 3 are populated programatically (by separate SQL queries to other tables).
I populate those columns by handling the CellValueNeeded event.
I receive all the data i need, but very slowly. Repainting of the cells in DGV is done one by one. But this isn't the most strange thing.

Strangest thing is, that CellValueNeeded is fired every time I hover the mouse over the programatically populated cell. Yes, hover the mouse. No clicking, or any other action.

No other events except CellValuePushed and CellValidating are handled. Value visible in a cell doesn't dissapear nor it's changed in any way. But of course query is sent to the database every time i hover over a cell. Hilarious...

I even check in the CellValueNeeded If e.Value = Nothing, but it's Nothing, even on mouse over.

I have no idea what may be causing this...
 
Last edited:
Not done much in virtual mode but the reason this is happening is because the CellValueNeeded event is fired every time the cell needs to be painted. So a solution mybae to cache the information from the server in a collection to prevent the application from making a round trip to the server.

Also with a bit of fancy API it maybe possible to use the GetMessageA function, or subclass using a Native Window to determine when a WM_PAINT message is sent to the window and consume it, however without testing it i couldn't be sure as to what effect this may have.
 
Thank you.

I've tried to populate the DGV completely manually, by first getting data to a collection:

VB.NET:
Public Structure pracownik
Public Id As Integer
Public nazwisko As String
Public EH As Single
Public Spoznienia As Single
Public Premia_wpisana As Single
End Structure
 
Public tabelka As New List(Of pracownik)
Dim p as pracownik
p.Id = blabla
...
tabelka.add(p)
And ok, I have the data there. But I'm having problems binding the list to the DGV. I've added columns manually:
VB.NET:
Dim KolNr As New DataGridViewColumn
KolNr.Name = "Id"
KolNr.HeaderText = "Nr."
KolNr.ReadOnly = True
KolNr.DataPropertyName = "id"
DataGridView2.Columns.Add(KolNr)
and finally binding the list through a bindingsource to the DGV:

VB.NET:
Me.BindingSource1.DataSource = tabelka
Me.DataGridView2.DataSource = BindingSource1
But all I receive is empty rows with no data....
 
Last edited by a moderator:
Back
Top