How do I get a listview to scroll over so a sub item is visible?
Thanks!
Printable View
How do I get a listview to scroll over so a sub item is visible?
Thanks!
i cant seem to get what you mean, can you clarify more
Well I was doing an all API approach till i remembered this
VB Code:
Private Sub ScrollToItem(ByRef lv As ListView, ByVal item As String, column As Long) Dim Row As Long Row = lv.FindItem(item, column) lv.ListItems(Row + 1).EnsureVisible lv.ListItems(Row + 1).Selected = True End Sub
ScrollToItem ListView1, "83hfhnhf/A", 1
Looks like you missed that part, remix... :)Quote:
Originally Posted by Static
I read it, but i thought he wanted the whole row highlighted..Well I suck at life :afrog:
The following code will scroll a specified column into view.VB Code:
Private Declare Function SendMessage _ Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByRef lParam As Any _ ) As Long Public Sub EnsureVisible( _ lv As ListView, Item As ListItem, SubColumn As Long) Const LVM_FIRST As Long = &H1000 Const LVM_SCROLL As Long = (LVM_FIRST + 20) Dim i As Long Dim iX As Long Item.EnsureVisible 'Only do the horizontal scrolling if we are in report view If lv.View = lvwReport Then If SubColumn > 0 And SubColumn <= Item.ListSubItems.Count Then For i = 1 To SubColumn + 1 iX = iX + lv.ColumnHeaders(i).Width Next iX = (iX - lv.Width) \ Screen.TwipsPerPixelX 'First make sure we are fully scrolled to the left Call SendMessage(lv.hWnd, LVM_SCROLL, -10000, ByVal 0) If iX > 0 Then 'Now scroll to the right Call SendMessage(lv.hWnd, LVM_SCROLL, iX, ByVal 0) End If End If End If End Sub
Thanks Joacim! Perfect
I'm sure Joacim Andersson's solution may be ok...but I adapted it for vhGrid. The only issue is the Column headers get mixed-up and cann't refresh.
LucasMKGCode:EDIT::
'vhGrid
'virtual listview
Public Sub CellEnsureVisible(ByVal SubColumn As Long)
Dim tRClt As RECT
Dim tRect As RECT
Dim iX As Long
'Only do the horizontal scrolling if we are in grid or report view
GetClientRect m_lHGHwnd, tRClt
CellCalcRect RowInFocus, SubColumn, tRect
With tRect
If .Right > tRClt.Right Then iX = (.Right - tRClt.Right)
If .left < tRClt.left Then iX = (.left - tRClt.left)
Call SendMessageLongA(m_lHGHwnd, LVM_SCROLL, iX, ByVal 0) 'Now scroll to the right or left
End With
End Sub::
getting to the innards of listview
What do you mean the column headers get mixed up? Something there is rearranging column order? There's always HDM_ORDERTOINDEX, but I've never needed it even refreshing columns after rearranging their order.
- see, attached
All the refreshing methods seems not to work
LucasMKGCode:Call SendMessage(m_lHdrHwnd, LVM_REDRAWITEMS, TopIndex, ByVal PageCount)
Call SendMessage(m_lHdrHwnd, LVM_UPDATE, TopIndex + PageCount, ByVal 0)
SendMessageLongA m_lHdrHwnd, WM_PAINT, 0&, 0&
EraseRect m_lHdrHwnd, tRect, 0&
UpdateWindow m_lHdrHwnd
UserControl.Refresh
?
What is the problem exactly? Can't tell from the picture.
When I move to the right/left the control behaves correctly but the column header is static
- when I remove HDM_LAYOUT in myWndProc (GXISubclass_WndProc) it behaves correctly...it might have to do with the WINDOWPOS flags
RESOLVED
EDIT::
- 'SWP_NOMOVE' :: was he culprit...for causing Header not to scroll.Code:'MyWndProc (GXISubclass_WndProc)
Case HDM_LAYOUT
If Not m_bHeaderHide Then
'/! hey m$, where's the f***ing documentation?
CopyMemory tHDL, ByVal lParam, Len(tHDL)
CopyMemory tWPos, ByVal tHDL.lpwpos, Len(tWPos)
CopyMemory tRect, ByVal tHDL.lprc, Len(tRect)
'/* setwinpos struct
With tWPos
.hWnd = m_lHdrHwnd
.hWndInsertAfter = 0&
.cx = (tRect.Right - tRect.left)
.cy = m_lHeaderHeight
.x = tRect.left
.y = 0&
'rem.Seal .flags = SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_NOMOVE
.flags = SWP_NOACTIVATE Or SWP_NOZORDER
End With
'/* adjust client rect
tRect.top = m_lHeaderHeight + 2
'/* copy and forward
CopyMemory ByVal tHDL.lprc, tRect, Len(tRect)
CopyMemory ByVal tHDL.lpwpos, tWPos, Len(tWPos)
CopyMemory ByVal lParam, tHDL, Len(tHDL)
' lReturn = lParam
bHandled = True
End If
Thanks fafalone for ensuring that I'm always sorted.
LucasMKG
hala to VBForums moderators