Post by Tasp on May 24, 2020 7:41:38 GMT -5
Why is Listview not native to LB!! So pretty to display multiple lines of data.
I've searched thru multiple examples and I'm currently using the following listview demo. Which seems the "easiest" to use.
What I can't find is a way to resize the listview in relation to window. My first thought was just to grab the sizes the user dragged to then reopen the window with the new values. but theres got to be a nicer way of doing that?
My original plan was this
But this just draws another listview, but 7/10 for effort!
I've searched thru multiple examples and I'm currently using the following listview demo. Which seems the "easiest" to use.
What I can't find is a way to resize the listview in relation to window. My first thought was just to grab the sizes the user dragged to then reopen the window with the new values. but theres got to be a nicer way of doing that?
'Brandon.bas
'NoMainWin
Global False : False = 0
Global True : True = 1
Global currentRow : currentRow = 0
'Global EditFlag : EditFlag = 0
global dataitem
listViewHandle(0) = _NULL
Call initializeListViewConstants
WindowWidth = 1000
WindowHeight = 800
Button #Example.btnAddItem, "Add Item", AddItem, UL, 5, (WindowHeight - 65)
Button #Example.GetMsgHookCallback, "Edit Item" , Checkedit ,UL, 960, 45 ,100 ,25
Open "ListView Example" For Window As #Example
Call InitCommonControls
style = _WS_CHILD Or _WS_VISIBLE Or listViewConstants.LVS.NOSORTHEADER.struct Or listViewConstants.LVS.REPORT.struct Or listViewConstants.LVS.SHOWSELALWAYS.struct Or listViewConstants.LVS.SINGLESEL.struct
styleEx = _WS_EX_CLIENTEDGE Or _WS_EX_DLGMODALFRAME 'Or listViewConstants.LVS.EX.DOUBLEBUFFER.struct
listViewHandle(0) = CreateListView(style, styleEx, Hwnd(#Example), GetWindowLong(Hwnd(#Example), _GWL_HINSTANCE), 5, 23, 800, 500)
result = setListViewFullRowSelect(listViewHandle(0))
result = listViewShowGrid(listViewHandle(0))
result = createNewListColumn(listViewHandle(0), 0, 100, " Item 1")
result = createNewListColumn(listViewHandle(0), 1, 100, " Item 2")
result = createNewListColumn(listViewHandle(0), 2, 100, " Item 3")
result = createNewListColumn(listViewHandle(0), 3, 100, " Item 4")
result = createNewListColumn(listViewHandle(0), 4, 100, " Item 5")
result = createNewListColumn(listViewHandle(0), 5, 100, " Item 6")
#Example "TrapClose Quit"
hParent=Hwnd(#Example) 'ADDED for my Understanding
hLV01 = listViewHandle(0)
open "Lib\MsgHook" for dll as #MsgHook
hMsgProc = hwnd(#Example.GetMsgHookCallback)
calldll #MsgHook, "TrapMsgFor",hLV01 as ulong, ret as boolean
calldll #MsgHook, "WatchMsg", hLV01 as ulong, _WM_LBUTTONDBLCLK as long, ret as boolean
hMsgProc = hwnd(#Example.GetMsgHookCallback)
calldll #user32, "GetWindowLongA",hMsgProc as ulong,_GWL_ID as short,callbackID as long
calldll #MsgHook, "CreateGetMsgProcHook",hParent as ulong, callbackID as long, _
hMsgProc as ulong, hHook as ulong
'CHECK HANDLES
print hLV01;" this is ListView handle hLV01"
print hParent;" this is hParent Handle"
print
WAIT
Sub Quit handle$
calldll #MsgHook, "UnhookMsgHook", hHook as ulong, ret as void
close #MsgHook
result = DestroyWindow(listViewHandle(0))
Close #handle$
End
End Sub
Sub AddItem handle$
dataitem = dataitem +1
result = AddListViewData(listViewHandle(0), currentRow, 0, "Data " ; dataitem)
result = EditListViewData(listViewHandle(0), currentRow, 1, "Data "; dataitem)
result = EditListViewData(listViewHandle(0), currentRow, 2, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 3, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 4, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 5, "Data ")
result = SelectListViewRow(listViewHandle(0), currentRow, True)
currentRow = (currentRow + 1)
End Sub
Sub InitCommonControls
CallDLL #comctl32, "InitCommonControls", ret As void
End Sub
Sub initializeListViewConstants
'Create the structs for ListViews
Struct LVITEM, mask As ulong, _
iItem As long, _
iSubItem As long, _
state As ulong, _
stateMask As ulong,_
pszText As ptr, _
cchTextMax As long, _
iImage As long, _
lParam As long, _
iIndent As long
Struct LVCOLUMN, mask As ulong, _
fmt As long, _
cx As long, _
pszText As ptr, _
cchTextMax As long, _
iSubItem As long, _
iImage As long, _
iOrder As long
Struct LVFINDINFO, flags As ulong, _
psz As ptr, _
lParam As ulong, _
pt As ulong, _ 'point structure
vkDirection As ulong
Struct listViewConstants, LVP.DBLCLK As long, _
LVS.REPORT As long, _
LVS.SINGLESEL As long, _
LVS.SHOWSELALWAYS As long, _
LVS.NOSORTHEADER As long, _
LVS.EXDOUBLEBUFFER As long, _
LVS.EX.FULLROWSELECT As long, _
LVS.EX.CHECKBOXES As long, _
LVIS.FOCUSED As long, _
LVIS.UNSELECTED As long, _
LVIS.SELECTED As long, _
LVIS.CHECKED As long, _
LVIS.UNCHECKED As long, _
LVIS.STATEIMAGEMASK As long, _
LVIF.TEXT As long, _
LVIF.STATE As long, _
LVIR.BOUNDS As long, _
LVFI.STRING As long, _
LVFI.PARTIAL As long, _
LVN.ITEMCHANGED As long, _
LVM.ENSUREVISIBLE As long, _
LVM.SETITEMSTATE As long, _
LVM.GETITEMSTATE As long, _
LVM.GETITEMTEXT As long, _
LVM.FINDITEMA As long, _
LVM.SETITEM As long, _
LVM.GETITEMCOUNT As long, _
LVM.GETITEMA As long, _
LVM.GETSUBITEMRECT As long, _
LVM.DELETEITEM As long, _
LVM.INSERTITEM As long, _
LVM.INSERTCOLUMN As long, _
LVM.SETEXTENDEDLISTVIEWSTYLE As long
'LVM_FIRST = &H1000 or 4096
listViewConstants.LVP.DBLCLK.struct = False
listViewConstants.LVS.REPORT.struct = 1
listViewConstants.LVS.SINGLESEL.struct = 4
listViewConstants.LVS.SHOWSELALWAYS.struct = 8
listViewConstants.LVS.NOSORTHEADER.struct = 32768
listViewConstants.LVS.EXDOUBLEBUFFER.struct = 10000
listViewConstants.LVS.EX.FULLROWSELECT.struct = 32
listViewConstants.LVS.EX.CHECKBOXES.struct = 4
listViewConstants.LVIS.FOCUSED.struct = 1
listViewConstants.LVIS.UNSELECTED.struct = 0
listViewConstants.LVIS.SELECTED.struct = 2
listViewConstants.LVIS.CHECKED.struct = 8192
listViewConstants.LVIS.UNCHECKED.struct = 4096
listViewConstants.LVIS.STATEIMAGEMASK.struct = 61440
listViewConstants.LVIF.TEXT.struct = 1
listViewConstants.LVIF.STATE.struct = 8
listViewConstants.LVIR.BOUNDS.struct = 0
listViewConstants.LVFI.STRING.struct = 2
listViewConstants.LVFI.PARTIAL.struct = 8
listViewConstants.LVN.ITEMCHANGED.struct = -101
listViewConstants.LVM.ENSUREVISIBLE.struct = 4115
listViewConstants.LVM.SETITEMSTATE.struct = 4139
listViewConstants.LVM.GETITEMSTATE.struct = 4140
listViewConstants.LVM.GETITEMTEXT.struct = 4141
listViewConstants.LVM.FINDITEMA.struct = 4109
listViewConstants.LVM.SETITEM.struct = 4102
listViewConstants.LVM.GETITEMCOUNT.struct = 4100
listViewConstants.LVM.GETITEMA.struct = 4101
listViewConstants.LVM.GETSUBITEMRECT.struct = 4152
listViewConstants.LVM.DELETEITEM.struct = 4104
listViewConstants.LVM.INSERTITEM.struct = 4103
listViewConstants.LVM.INSERTCOLUMN.struct = 4123
listViewConstants.LVM.SETEXTENDEDLISTVIEWSTYLE.struct = 4150
End Sub
Function CreateListView(ByRef style, ByRef styleEx, ByRef hParent, ByRef hInstance, ByRef xloc, ByRef yloc, ByRef width, ByRef height)
className$ = "SysListView32" + chr$(0)
CallDLL #user32, "CreateWindowExA", styleEx As ulong, _ ' extended style
className$ As ptr, _ ' class name
"" As ptr, _
style As ulong, _ ' style
xloc As long, _ ' left x
yloc As long, _ ' top y
width As long, _ ' width
height As long, _ ' height
hParent As ulong, _ ' parent hWnd
_NULL As ulong, _
hInstance As ulong, _ ' hInstance
_NULL As ulong, _
CreateListView As ulong 'Hwnd to ListView
'LVCF.WIDTH = 2 : LVCF.TEXT = 4
LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT
print hParent;" hParent in the CreateListView Function"
End Function
Function GetWindowLong(hWnd, index)
CallDLL #user32, "GetWindowLongA", hWnd As ulong, _
index As long, _
GetWindowLong As long
print GetWindowLong;" GetWindowLong"
print hWnd ;" hWnd"
End Function
Function GetListViewItemCount(hWndLV)
GetListViewItemCount = SendMessage(hWndLV, listViewConstants.LVM.GETITEMCOUNT.struct, 0, 0)
End Function
Function createNewListColumn(hListView, columnIndex, columnWidth, headerCaption$)
LVCOLUMN.cx.struct = columnWidth
LVCOLUMN.pszText.struct = headerCaption$
LVCF.WIDTH = 2 : LVCF.TEXT = 4
LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT
createNewListColumn = SendMessageLVCOLUMNStruct(hListView, listViewConstants.LVM.INSERTCOLUMN.struct, columnIndex)
End Function
Function AddListViewData(hWndLV, row, column, myData$)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = myData$
result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.INSERTITEM.struct, 0)
AddListViewData = SendMessage(hWndLV, listViewConstants.LVM.GETITEMSTATE.struct, 0, 0)
End Function
Function EditListViewData(hWndLV, row, column, myData$)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = myData$
EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0)
End Function
Function SelectListViewRow(hWndLV, row, setFocus)
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = 0
LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct
LVITEM.state.struct = listViewConstants.LVIS.SELECTED.struct
If setFocus = True Then
LVITEM.state.struct = (LVITEM.state.struct Or listViewConstants.LVIS.FOCUSED.struct)
End If
'SelectListViewRow = SetFocus(hWndLV)
SelectListViewRow = SendMessage(hWndLV, listViewConstants.LVM.ENSUREVISIBLE.struct, row, False)
SelectListViewRow = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0)
End Function
Function setListViewFullRowSelect(hListView)
setListViewFullRowSelect = SendMessage(hListView, 4150, 32, 32)'LVS_EX_FULLROWSELECT
End Function
Function listViewShowGrid(hListView)
listViewShowGrid = SendMessage(hListView, 4150, 1, 1)'LVS_EX_GRIDLINES
End Function
Function SendMessage(hWnd, Msg, wParam, lParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
lParam As long, _
SendMessage As long
End Function
Function SendMessageLVITEMStruct(hWnd, Msg, wParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
LVITEM As struct, _
SendMessageLVITEMStruct As long
End Function
Function SendMessageLVCOLUMNStruct(hWnd, Msg, wParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
LVCOLUMN As struct, _
SendMessageLVCOLUMNStruct As long
End Function
Function DestroyWindow(hWnd)
CallDLL #user32, "DestroyWindow", hWnd As ulong, _
DestroyWindow As long
End Function
Function GetSelectedListViewRow(hWndLV)
GetSelectedListViewRow = -1
numListViewEntries = GetListViewItemCount(hWndLV)
For row = 0 To (numListViewEntries - 1)
LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = 0 'first column
LVITEM.stateMask.struct = listViewConstants.LVIS.SELECTED.struct
result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMA.struct, 0)
If LVITEM.state.struct And listViewConstants.LVIS.SELECTED.struct Then
GetSelectedListViewRow = row
Exit Function
Else
If row = (numListViewEntries - 1) Then
GetSelectedListViewRow = -1
Exit Function
End If
End If
Next row
End Function
Function GetListViewText$(hWndLV, row, column)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = Space$(_MAX_PATH) + chr$(0)
LVITEM.cchTextMax.struct = Len(Winstring(LVITEM.pszText.struct))
EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMTEXT.struct, row)
GetListViewText$ = Trim$(Winstring(LVITEM.pszText.struct))
End Function
My original plan was this
'Brandon.bas
'NoMainWin
Global False : False = 0
Global True : True = 1
Global currentRow : currentRow = 0
'Global EditFlag : EditFlag = 0
global dataitem
listViewHandle(0) = _NULL
Call initializeListViewConstants
WindowWidth = 1000
WindowHeight = 800
Button #Example.btnAddItem, "Add Item", AddItem, UL, 5, (WindowHeight - 65)
Button #Example.GetMsgHookCallback, "Edit Item" , Checkedit ,UL, 960, 45 ,100 ,25
Open "ListView Example" For Window As #Example
nomainwin
Call InitCommonControls
CALL DrawListView handle$
#Example "TrapClose Quit"
hParent=Hwnd(#Example) 'ADDED for my Understanding
hLV01 = listViewHandle(0)
open "Lib\MsgHook" for dll as #MsgHook
hMsgProc = hwnd(#Example.GetMsgHookCallback)
calldll #MsgHook, "TrapMsgFor",hLV01 as ulong, ret as boolean
calldll #MsgHook, "WatchMsg", hLV01 as ulong, _WM_LBUTTONDBLCLK as long, ret as boolean
hMsgProc = hwnd(#Example.GetMsgHookCallback)
calldll #user32, "GetWindowLongA",hMsgProc as ulong,_GWL_ID as short,callbackID as long
calldll #MsgHook, "CreateGetMsgProcHook",hParent as ulong, callbackID as long, _
hMsgProc as ulong, hHook as ulong
#Example, "resizehandler DrawListView"
WAIT
Sub Quit handle$
calldll #MsgHook, "UnhookMsgHook", hHook as ulong, ret as void
close #MsgHook
result = DestroyWindow(listViewHandle(0))
Close #handle$
End
End Sub
SUB DrawListView handle$
style = _WS_CHILD Or _WS_VISIBLE Or listViewConstants.LVS.NOSORTHEADER.struct Or listViewConstants.LVS.REPORT.struct Or listViewConstants.LVS.SHOWSELALWAYS.struct Or listViewConstants.LVS.SINGLESEL.struct
styleEx = _WS_EX_CLIENTEDGE Or _WS_EX_DLGMODALFRAME 'Or listViewConstants.LVS.EX.DOUBLEBUFFER.struct
listViewHandle(0) = CreateListView(style, styleEx, Hwnd(#Example), GetWindowLong(Hwnd(#Example), _GWL_HINSTANCE), 5, 23, WindowWidth - 100, WindowHeight - 100)
result = setListViewFullRowSelect(listViewHandle(0))
result = listViewShowGrid(listViewHandle(0))
result = createNewListColumn(listViewHandle(0), 0, 100, " Item 1")
result = createNewListColumn(listViewHandle(0), 1, 150, " Item 2")
result = createNewListColumn(listViewHandle(0), 2, 100, " Item 3")
result = createNewListColumn(listViewHandle(0), 3, 100, " Item 4")
result = createNewListColumn(listViewHandle(0), 4, 100, " Item 5")
result = createNewListColumn(listViewHandle(0), 5, 100, " Item 6")
END SUB
WAIT
Sub AddItem handle$
dataitem = dataitem +1
result = AddListViewData(listViewHandle(0), currentRow, 0, "Data " ; dataitem)
result = EditListViewData(listViewHandle(0), currentRow, 1, "Data "; dataitem)
result = EditListViewData(listViewHandle(0), currentRow, 2, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 3, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 4, "Data ")
result = EditListViewData(listViewHandle(0), currentRow, 5, "Data ")
result = SelectListViewRow(listViewHandle(0), currentRow, True)
currentRow = (currentRow + 1)
End Sub
Sub InitCommonControls
CallDLL #comctl32, "InitCommonControls", ret As void
End Sub
Sub initializeListViewConstants
'Create the structs for ListViews
Struct LVITEM, mask As ulong, _
iItem As long, _
iSubItem As long, _
state As ulong, _
stateMask As ulong,_
pszText As ptr, _
cchTextMax As long, _
iImage As long, _
lParam As long, _
iIndent As long
Struct LVCOLUMN, mask As ulong, _
fmt As long, _
cx As long, _
pszText As ptr, _
cchTextMax As long, _
iSubItem As long, _
iImage As long, _
iOrder As long
Struct LVFINDINFO, flags As ulong, _
psz As ptr, _
lParam As ulong, _
pt As ulong, _ 'point structure
vkDirection As ulong
Struct listViewConstants, LVP.DBLCLK As long, _
LVS.REPORT As long, _
LVS.SINGLESEL As long, _
LVS.SHOWSELALWAYS As long, _
LVS.NOSORTHEADER As long, _
LVS.EXDOUBLEBUFFER As long, _
LVS.EX.FULLROWSELECT As long, _
LVS.EX.CHECKBOXES As long, _
LVIS.FOCUSED As long, _
LVIS.UNSELECTED As long, _
LVIS.SELECTED As long, _
LVIS.CHECKED As long, _
LVIS.UNCHECKED As long, _
LVIS.STATEIMAGEMASK As long, _
LVIF.TEXT As long, _
LVIF.STATE As long, _
LVIR.BOUNDS As long, _
LVFI.STRING As long, _
LVFI.PARTIAL As long, _
LVN.ITEMCHANGED As long, _
LVM.ENSUREVISIBLE As long, _
LVM.SETITEMSTATE As long, _
LVM.GETITEMSTATE As long, _
LVM.GETITEMTEXT As long, _
LVM.FINDITEMA As long, _
LVM.SETITEM As long, _
LVM.GETITEMCOUNT As long, _
LVM.GETITEMA As long, _
LVM.GETSUBITEMRECT As long, _
LVM.DELETEITEM As long, _
LVM.INSERTITEM As long, _
LVM.INSERTCOLUMN As long, _
LVM.SETEXTENDEDLISTVIEWSTYLE As long
'LVM_FIRST = &H1000 or 4096
listViewConstants.LVP.DBLCLK.struct = False
listViewConstants.LVS.REPORT.struct = 1
listViewConstants.LVS.SINGLESEL.struct = 4
listViewConstants.LVS.SHOWSELALWAYS.struct = 8
listViewConstants.LVS.NOSORTHEADER.struct = 32768
listViewConstants.LVS.EXDOUBLEBUFFER.struct = 10000
listViewConstants.LVS.EX.FULLROWSELECT.struct = 32
listViewConstants.LVS.EX.CHECKBOXES.struct = 4
listViewConstants.LVIS.FOCUSED.struct = 1
listViewConstants.LVIS.UNSELECTED.struct = 0
listViewConstants.LVIS.SELECTED.struct = 2
listViewConstants.LVIS.CHECKED.struct = 8192
listViewConstants.LVIS.UNCHECKED.struct = 4096
listViewConstants.LVIS.STATEIMAGEMASK.struct = 61440
listViewConstants.LVIF.TEXT.struct = 1
listViewConstants.LVIF.STATE.struct = 8
listViewConstants.LVIR.BOUNDS.struct = 0
listViewConstants.LVFI.STRING.struct = 2
listViewConstants.LVFI.PARTIAL.struct = 8
listViewConstants.LVN.ITEMCHANGED.struct = -101
listViewConstants.LVM.ENSUREVISIBLE.struct = 4115
listViewConstants.LVM.SETITEMSTATE.struct = 4139
listViewConstants.LVM.GETITEMSTATE.struct = 4140
listViewConstants.LVM.GETITEMTEXT.struct = 4141
listViewConstants.LVM.FINDITEMA.struct = 4109
listViewConstants.LVM.SETITEM.struct = 4102
listViewConstants.LVM.GETITEMCOUNT.struct = 4100
listViewConstants.LVM.GETITEMA.struct = 4101
listViewConstants.LVM.GETSUBITEMRECT.struct = 4152
listViewConstants.LVM.DELETEITEM.struct = 4104
listViewConstants.LVM.INSERTITEM.struct = 4103
listViewConstants.LVM.INSERTCOLUMN.struct = 4123
listViewConstants.LVM.SETEXTENDEDLISTVIEWSTYLE.struct = 4150
End Sub
Function CreateListView(ByRef style, ByRef styleEx, ByRef hParent, ByRef hInstance, ByRef xloc, ByRef yloc, ByRef width, ByRef height)
className$ = "SysListView32" + chr$(0)
CallDLL #user32, "CreateWindowExA", styleEx As ulong, _ ' extended style
className$ As ptr, _ ' class name
"" As ptr, _
style As ulong, _ ' style
xloc As long, _ ' left x
yloc As long, _ ' top y
width As long, _ ' width
height As long, _ ' height
hParent As ulong, _ ' parent hWnd
_NULL As ulong, _
hInstance As ulong, _ ' hInstance
_NULL As ulong, _
CreateListView As ulong 'Hwnd to ListView
'LVCF.WIDTH = 2 : LVCF.TEXT = 4
LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT
print hParent;" hParent in the CreateListView Function"
End Function
Function GetWindowLong(hWnd, index)
CallDLL #user32, "GetWindowLongA", hWnd As ulong, _
index As long, _
GetWindowLong As long
print GetWindowLong;" GetWindowLong"
print hWnd ;" hWnd"
End Function
Function GetListViewItemCount(hWndLV)
GetListViewItemCount = SendMessage(hWndLV, listViewConstants.LVM.GETITEMCOUNT.struct, 0, 0)
End Function
Function createNewListColumn(hListView, columnIndex, columnWidth, headerCaption$)
LVCOLUMN.cx.struct = columnWidth
LVCOLUMN.pszText.struct = headerCaption$
LVCF.WIDTH = 2 : LVCF.TEXT = 4
LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT
createNewListColumn = SendMessageLVCOLUMNStruct(hListView, listViewConstants.LVM.INSERTCOLUMN.struct, columnIndex)
End Function
Function AddListViewData(hWndLV, row, column, myData$)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = myData$
result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.INSERTITEM.struct, 0)
AddListViewData = SendMessage(hWndLV, listViewConstants.LVM.GETITEMSTATE.struct, 0, 0)
End Function
Function EditListViewData(hWndLV, row, column, myData$)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = myData$
EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0)
End Function
Function SelectListViewRow(hWndLV, row, setFocus)
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = 0
LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct
LVITEM.state.struct = listViewConstants.LVIS.SELECTED.struct
If setFocus = True Then
LVITEM.state.struct = (LVITEM.state.struct Or listViewConstants.LVIS.FOCUSED.struct)
End If
'SelectListViewRow = SetFocus(hWndLV)
SelectListViewRow = SendMessage(hWndLV, listViewConstants.LVM.ENSUREVISIBLE.struct, row, False)
SelectListViewRow = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0)
End Function
Function setListViewFullRowSelect(hListView)
setListViewFullRowSelect = SendMessage(hListView, 4150, 32, 32)'LVS_EX_FULLROWSELECT
End Function
Function listViewShowGrid(hListView)
listViewShowGrid = SendMessage(hListView, 4150, 1, 1)'LVS_EX_GRIDLINES
End Function
Function SendMessage(hWnd, Msg, wParam, lParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
lParam As long, _
SendMessage As long
End Function
Function SendMessageLVITEMStruct(hWnd, Msg, wParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
LVITEM As struct, _
SendMessageLVITEMStruct As long
End Function
Function SendMessageLVCOLUMNStruct(hWnd, Msg, wParam)
CallDLL #user32, "SendMessageA" , hWnd As ulong, _
Msg As long, _
wParam As long, _
LVCOLUMN As struct, _
SendMessageLVCOLUMNStruct As long
End Function
Function DestroyWindow(hWnd)
CallDLL #user32, "DestroyWindow", hWnd As ulong, _
DestroyWindow As long
End Function
Function GetSelectedListViewRow(hWndLV)
GetSelectedListViewRow = -1
numListViewEntries = GetListViewItemCount(hWndLV)
For row = 0 To (numListViewEntries - 1)
LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct
LVITEM.iItem.struct = row
LVITEM.iSubItem.struct = 0 'first column
LVITEM.stateMask.struct = listViewConstants.LVIS.SELECTED.struct
result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMA.struct, 0)
If LVITEM.state.struct And listViewConstants.LVIS.SELECTED.struct Then
GetSelectedListViewRow = row
Exit Function
Else
If row = (numListViewEntries - 1) Then
GetSelectedListViewRow = -1
Exit Function
End If
End If
Next row
End Function
Function GetListViewText$(hWndLV, row, column)
LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct
LVITEM.iSubItem.struct = column
LVITEM.pszText.struct = Space$(_MAX_PATH) + chr$(0)
LVITEM.cchTextMax.struct = Len(Winstring(LVITEM.pszText.struct))
EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMTEXT.struct, row)
GetListViewText$ = Trim$(Winstring(LVITEM.pszText.struct))
End Function
But this just draws another listview, but 7/10 for effort!