Jump to content

ListView select and read help


Recommended Posts

Hi everyone, ;)

I have attached a file below, in the GUI there is a List View that displays a list of items, and theres an input box, i want it in such way that when you select an item from list, its automatically shown in the input box.

I tried to make it work for hours, but couldnt make it work, would really appreciate it if someone helps me out :)

thank you

GUI.au3

EDIT: PS here is other other GUI with which im having problem, you have to drag and drop files on combo to make file list

Good Luck with it :D

GUI 2.au3

GUIListViewEx.au3

Edited by ActualAkshay
Link to comment
Share on other sites

You do it just like line

Case $GUI_EVENT_CLOSE
. You'll only put variables of your ListViewItems. Also look in AutoIt's help file for GUICtrlRead() and GUICtrlSetData().

i tried everything, but i couldnt make it work at all,

I even tried using _GUIListViewEx_WM_LBUTTONUP_Handler from _GUIListViewEx UDF, _GUICtrlListView_GetItemText()

but nothing worked, GUICtrlRead() return strange numbers like 120, 121, 124

Link to comment
Share on other sites

yes right, if i trim the item number from StringTrimRight, _GUICtrlListView_GetItemText can be used to display the item, but whats the reason behind list view returning numbers? and cant items be directly returned by any other way that could make the program simple?

Edited by ActualAkshay
Link to comment
Share on other sites

Try this

Case $ListView1_2
   GUICtrlSetData($Input1,StringTrimRight(GUICtrlRead($ListView1_2),1))
  Case $ListView1_3
   GUICtrlSetData($Input1,StringTrimRight(GUICtrlRead($ListView1_3),1))

$ListView1_3 and $ListView1_2 can be repleaced with $nMsg

so here is other other GUI with which im having problem, you have to drag and drop files on combo to make file list

Good Luck with it ;)

GUI 2.au3

GUIListViewEx.au3

Link to comment
Share on other sites

Of course I have tried it and it worked.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListViewEx.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", 1)
;~ Global $WM_DROPFILES = 0x233
Global $DropFilesArr[1], $IDs[10], $counter=0
Local $FileList, $CancelB, $TitleC

_GUICreate()
_SetOnEvents()
$sel_file_index = 0
While 1
Sleep(10)
WEnd
Func _GUICreate()
#Region ### START Koda GUI section ### Form=Form2 (2).kxf
$GUI = GUICreate("Akshay", 608, 376, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, ""))
$TitleC = GUICtrlCreateInput("", 74, 59, 256, 25) ;, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_GROUP))
$FileList = GUICtrlCreateListView("Name", 376, 8, 224, 360, BitOR($LVS_SHOWSELALWAYS, $WS_HSCROLL))
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
#EndRegion ### END Koda GUI section ###
EndFunc   ;==>_GUICreate
Func _GUIDelete()
GUIDelete()
EndFunc   ;==>_GUIDelete
Func _Exit()
Exit
EndFunc   ;==>_Exit
Func _SetOnEvents()
GUISetOnEvent($GUI_EVENT_DROPPED, "_DragFileFill")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
EndFunc   ;==>_SetOnEvents

Func _DragFileFill()
$NotValidExtPath = ""
$ValidExtCount = 0
For $i = 1 To UBound($DropFilesArr) - 1
;~   If (UBound($IDs))>$counter Then ReDim $IDs[2*UBound($IDs)]
;~   ConsoleWrite("$counter=" & $counter)
  $ValidExtCount += 1
;~   $counter=$counter+1
  GUICtrlCreateListViewItem($DropFilesArr[$i], $FileList)
  GUICtrlSetOnEvent(-1,"Set")
Next
If $ValidExtCount > 0 Then GUICtrlSendMsg($FileList, $LVM_SETCOLUMNWIDTH, 0, -1)
_GUICtrlListView_SetItemSelected($FileList, 0)
EndFunc   ;==>_DragFileFill
Func _File_Selected()
$sel_file_text = _GUICtrlListView_GetItemText($FileList, GUICtrlRead($FileList))
GUICtrlSetData($TitleC, $sel_file_text)
EndFunc   ;==>_File_Selected
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
For $i = 0 To $nAmt[0] - 1
  $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
  $nSize = $nSize[0] + 1
  $pFileName = DllStructCreate("char[" & $nSize & "]")
  DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
    DllStructGetPtr($pFileName), "int", $nSize)
  ReDim $DropFilesArr[$i + 2]
  $DropFilesArr[$i + 1] = DllStructGetData($pFileName, 1)
  $pFileName = 0
Next
$DropFilesArr[0] = UBound($DropFilesArr) - 1
EndFunc   ;==>WM_DROPFILES_FUNC
Func Set()
GUICtrlSetData($TitleC,GUICtrlRead(@GUI_CtrlId))
EndFunc
I think that the function in you while loop you had, the one in the same line with If... , was for GUIRegister Message()

Link to comment
Share on other sites

Of course I have tried it and it worked.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListViewEx.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", 1)
;~ Global $WM_DROPFILES = 0x233
Global $DropFilesArr[1], $IDs[10], $counter=0
Local $FileList, $CancelB, $TitleC

_GUICreate()
_SetOnEvents()
$sel_file_index = 0
While 1
Sleep(10)
WEnd
Func _GUICreate()
#Region ### START Koda GUI section ### Form=Form2 (2).kxf
$GUI = GUICreate("Akshay", 608, 376, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, ""))
$TitleC = GUICtrlCreateInput("", 74, 59, 256, 25) ;, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_GROUP))
$FileList = GUICtrlCreateListView("Name", 376, 8, 224, 360, BitOR($LVS_SHOWSELALWAYS, $WS_HSCROLL))
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
#EndRegion ### END Koda GUI section ###
EndFunc   ;==>_GUICreate
Func _GUIDelete()
GUIDelete()
EndFunc   ;==>_GUIDelete
Func _Exit()
Exit
EndFunc   ;==>_Exit
Func _SetOnEvents()
GUISetOnEvent($GUI_EVENT_DROPPED, "_DragFileFill")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
EndFunc   ;==>_SetOnEvents

Func _DragFileFill()
$NotValidExtPath = ""
$ValidExtCount = 0
For $i = 1 To UBound($DropFilesArr) - 1
;~   If (UBound($IDs))>$counter Then ReDim $IDs[2*UBound($IDs)]
;~   ConsoleWrite("$counter=" & $counter)
  $ValidExtCount += 1
;~   $counter=$counter+1
  GUICtrlCreateListViewItem($DropFilesArr[$i], $FileList)
  GUICtrlSetOnEvent(-1,"Set")
Next
If $ValidExtCount > 0 Then GUICtrlSendMsg($FileList, $LVM_SETCOLUMNWIDTH, 0, -1)
_GUICtrlListView_SetItemSelected($FileList, 0)
EndFunc   ;==>_DragFileFill
Func _File_Selected()
$sel_file_text = _GUICtrlListView_GetItemText($FileList, GUICtrlRead($FileList))
GUICtrlSetData($TitleC, $sel_file_text)
EndFunc   ;==>_File_Selected
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
For $i = 0 To $nAmt[0] - 1
  $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
  $nSize = $nSize[0] + 1
  $pFileName = DllStructCreate("char[" & $nSize & "]")
  DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
    DllStructGetPtr($pFileName), "int", $nSize)
  ReDim $DropFilesArr[$i + 2]
  $DropFilesArr[$i + 1] = DllStructGetData($pFileName, 1)
  $pFileName = 0
Next
$DropFilesArr[0] = UBound($DropFilesArr) - 1
EndFunc   ;==>WM_DROPFILES_FUNC
Func Set()
GUICtrlSetData($TitleC,GUICtrlRead(@GUI_CtrlId))
EndFunc
I think that the function in you while loop you had, the one in the same line with If... , was for GUIRegister Message()

Oh thanks a lot bro it worked, you rock!! thank you soooooo much ;)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...