wendy
01-27-2008, 11:46 AM
Hello,
I'm using SGrid 2.0 control since a few month and everything is working fine.
Now I added a second SGrid control to the same form and this is causing some headache to me :-(
I do have the following problems now:
The below code is used for grdConfChkOutput. Problem is how to manage the new control grdConfChkOutput2 ??
IGridCellOwnerDraw is drawing the custom style as far as I understood this control. However, how can I distinguish between control1 and control2?
Private Sub IGridCellOwnerDraw_Draw(cell As cGridCell, ByVal lHDC As Long, ByVal eDrawStage As ECGDrawStage, ByVal lLeft As Long, ByVal lTop As Long, ByVal lRight As Long, ByVal lBottom As Long, bSkipDefault As Boolean)
If (eDrawStage = ecgBeforeIconAndText) Then
If grdConfChkOutput.RowIsGroup(cell.Row) Then
drawGroupRow cell, lHDC, lLeft, lTop, lRight, lBottom
bSkipDefault = True
End If
End If
end sub
wendy
01-29-2008, 02:25 PM
I suppose I know how to solve this problem,but I need further support.
I need to get the lHDC value. I supposed this should be possible with GetDC...
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
... then using .hwnd as below ...
Private Sub IGridCellOwnerDraw_Draw(cell As cGridCell, ByVal lHDC As Long, ByVal eDrawStage As ECGDrawStage, ByVal lLeft As Long, ByVal lTop As Long, ByVal lRight As Long, ByVal lBottom As Long, bSkipDefault As Boolean)
Debug.Print GetDC(grdConfChkOutput.hwnd); lHDC
However, the debug output is different
results:
GetDC(grdConfChkOutput.hwnd): -1644096143
grdConfChkOutput.hwnd: -134146801
I expected that both values are the same, but doesn't work :(
Any idea??
many thanks
the master
01-29-2008, 03:57 PM
Im not sure about your actual problem but a DC handle is not the same as a wnd handle. GetDC() will get the DC handle based on the wnd handle that you provide. There is also GetCompatibleDC() but im not sure that anything like this would solve your problem.
I dont have anything called an SGrid control and its not something ive heard of before. Could you explain the setup a little more please. What is IGridCellOwnerDraw?
wendy
01-29-2008, 11:56 PM
Im not sure about your actual problem but a DC handle is not the same as a wnd handle. GetDC() will get the DC handle based on the wnd handle that you provide. There is also GetCompatibleDC() but im not sure that anything like this would solve your problem.
I dont have anything called an SGrid control and its not something ive heard of before. Could you explain the setup a little more please. What is IGridCellOwnerDraw?
SGrid 2 is a powerful control which I use for customized listview.
I do use the ListView as in the examples:
Creating ListView Style Groups with SGrid 2 (http://www.vbaccelerator.com/home/VB/Code/Controls/S_Grid_2/ListView_Style_Grouping/article.asp)
Owner-Draw Cells with SGrid 2.0 (http://www.vbaccelerator.com/home/VB/Code/Controls/S_Grid_2/OwnerDraw_Cells/article.asp)
With one control everything is working fine, but with two controls do have problem with the IGridCellOwnerDraw. Problem is, that only one control is visible at a time (used in Tabs Control), thus only this control need to be drawed.
the master
01-30-2008, 02:14 AM
Im not sure on the correct way of doing it but i think i might have a workaround.
From your second link
Private Sub Form_Load()
' Connect the grid to the owner-draw
' implementation:
grdOwnerDrawDemo.OwnerDrawImpl = Me
End Sub
I assume that is telling the grid which code module has the IGridCellOwnerDraw_Draw sub in it. I guess you could create a seperate module with the same sub (youwill probably need a *public* sub) then give the second grid the modules name instead.
Private Sub Form_Load()
' Connect the grid to the owner-draw
' implementation:
grdOwnerDrawDemo.OwnerDrawImpl = Me
grdSecondGrid.OwnerDrawImpl = module1
End Sub
If you only need 1 displaying at a time then would it not be possible to use the same control but switch between the data it displays?
wendy
01-30-2008, 11:28 PM
Hello,
this is the method I will use now. Thanks for the hint.
However it would be good to know how to get this lHDC value :rolleyes:
cheers