Jump to content

ListView DoubleClick set variables


 Share

Recommended Posts

I have a script that does a Access DB Query:

CODE
#include <GUIConstantsEx.au3>

#include <DBlistView.au3>

; MsgBox(0, "Info", " The scripts starts", 2)

Opt("GUIOnEventMode", 1) ; OnEvent mode

Dim $title="Access db Viewer" ;gui title

Dim $gui = GUICreate($title, 800, 600)

$DB=@ScriptDir & "\test.mdb"

If FileExists ($DB) Then

; continue on

Else

MsgBox(4096, "Error", $DB & " Does NOT exist!!!!")

Exit

EndIf

$Query="Select CompanyName,CompanyAddress1,CompanyState From CompanyName Order by CompanyName ASC"

;$Query="Select * From CompanyName Order by CompanyName ASC"

$Number_of_Records_to_Display = 25

$Listview_Left = 80

$Listview_Top = 80

$Listview_Width = 500

$Listview_Height = 500

$Listview_style = $GUI_SS_DEFAULT_LISTVIEW ;default is -1

$Listview_exStyle = $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES

_createDBlistView($DB,$Query,$Number_of_Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

GUISetOnEvent($GUI_EVENT_CLOSE, "ClickCLOSE")

GUISetState ()

While 1

Sleep(1000) ; Idle around

WEnd

Func OKClicked()

MsgBox(0, "OK Pressed", "OK Pressed", 4)

$loopvar = 0

;GUIDelete($GUI)

EndFunc

Func ClickCLOSE()

Exit

EndFunc

Func GoodBye()

MsgBox(4096,"", "Goodbye!")

Exit

EndFunc

Func DoubleClickFunc()

; set the variables here for the listview item that was doubleclicked.

MsgBox(64, "OK ", "You Double Clicked: ")

EndFunc

Can you point me in the right direction for the following? From the ListView display, when I double click a specific entry, I want to set variables I will use to call the entry:

IE: Query shows in the ListView box:

CompanyName CompanyAddress CompanyState

When entry was DoubleClicked in the above ListView box it set these variables:

CompanyTelephone CompanyUser CompanyID

I do not want the user to see all of the information returned from the query, only specific fields. However the DoubleClick needs to set additional variables.

How do I set specific variables for the clicked on item in the ListView when I DoubleClick it?

I looked through the Help File based on forum postings and looked at _GUICtrlTreeView_ClickItem and _GUICtrlTreeView_Create but neither appear to be what I am looking for. Any suggestions?

CC

Edited by IvanCodin
Link to comment
Share on other sites

what kind of variables are you talking about hire? please create small, simple & WORKING! example of what you want to do. No databases this time, just small list view , fill it with items & explain what must happen when you double click an item.

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Here is an example of what I am trying to do. Based on the original DB query that was ran I only want to show the col 2, 3, and 4 items to the user. When I DoubleClick on the ListView item I want to set variables for the col 4, 5, and 6 items to the required variables.

Based on your request for a standalone script this is the best I could come up with. I hope it's clear as to what I am trying to accomplish.

Example: DoubleClicked on item4

Variables set as follows:

CompanyTelephone = col44

CompanyUser = col45

CompanyID = col46

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()

Local $listview, $button, $item1, $item2, $item3, $item4, $item5, $item6, $item7, $item8, $msg

GUICreate("Set VARs from items", 220, 165, 200, 200, -1, $WS_EX_ACCEPTFILES)

GUISetBkColor(0x00E0FFFF) ; will change background color

$listview = GUICtrlCreateListView("col1 |col2|col3|col4|col5|col6|col7|col8 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)

;$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)

$item1 = GUICtrlCreateListViewItem("item1|col12|col13|col14|col15|col16|col17|col18", $listview)

$item2 = GUICtrlCreateListViewItem("item2|col22|col23|col24|col25|col26|col27|col28", $listview)

$item3 = GUICtrlCreateListViewItem("item3|col32|col33|col34|col35|col36|col37|col38", $listview)

$item4 = GUICtrlCreateListViewItem("item4|col42|col43|col44|col45|col46|col47|col48", $listview)

$item5 = GUICtrlCreateListViewItem("item5|col52|col53|col54|col55|col56|col57|col58", $listview)

$item6 = GUICtrlCreateListViewItem("item6|col62|col63|col64|col65|col66|col67|col68", $listview)

$item7 = GUICtrlCreateListViewItem("item7|col72|col73|col74|col75|col76|col77|col78", $listview)

$item8 = GUICtrlCreateListViewItem("item8|col82|col83|col84|col85|col86|col87|col88", $listview)

GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping

GUISetState()

Do

$msg = GUIGetMsg()

Until $msg = $GUI_EVENT_CLOSE

EndFunc ;==>Example

Thanks

CC

Edited by IvanCodin
Link to comment
Share on other sites

Let me see if I understand it correctly.

I think I know what you actually want. this is fairly simple Look it up in tht help file. This is how you make the listview. Yes I know it looks scary & loads of code, but you will just need a fraction of it:

_GUICtrlListView_Create

Hire is 1 small sample just to get you started: MAKE SHURE YOU CHECK OUT THE HELP FILE SAMPLE !!! this is just 1 half assed code.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

    
$Form1 = GUICreate('boo', 361, 270, 200, 200)

;~ Create listview 
    $hListView = _GUICtrlListView_Create ($Form1, "", 0, 0, 260, 377) ; LEFT],[TOP],WIDTH],[HEIGHT]
                 _GUICtrlListView_SetExtendedListViewStyle ($hListView, BitOR($LVS_AUTOARRANGE,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER,$LVS_EX_SUBITEMIMAGES))
                
  ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 150)
    
    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)

    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)


Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE



;~ ========================================================
;~ This thing is responcible for click events
;~ ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode                           
                
                Case $NM_DBLCLK  ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                   Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                   
                   $Index = DllStructGetData($tInfo, "Index")
                   
                   $subitemNR = DllStructGetData($tInfo, "SubItem")
                   
                   
                   ; make sure user clicks on the listview & only the activate
                   If $Index <> -1 Then
                       
                       ; col1 ITem index
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index),'|')
                        $item = $item[1]
                        
                        ;Col item 2 index
                        $item2 = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $subitemNR),'|')
                        $item2= $item2[2]                       
                        
                        ConsoleWrite($item & ' ' & $item2 & @CRLF)

                    EndIf
                    
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

  • 4 years later...

Universalist, thank you for the great example.

 

I need to modify it a bit.

 

I have an array with scale [6x4]. The last column (4th) in every row stores a link. So I need to open it making double-click on no matter what column in the row.

So.

click on cell 1x1 should open link from cell 1x4.

click on cell 2x3 should open link from cell 2x4,

click on cell 4x2 should open link from cell 4x4

 

...and so on.

 

I hope I was clear enough)))

 

Thank you!

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...