Jump to content

Function _GUICtrlListView_SetItemSelected to get information about multiple lines that are Focus to the last line(blinking)


Recommended Posts

Func Save()
    FileDelete(@ScriptDir&'\Test.txt')
    $list_count = _GUICtrlListView_GetItemCount ($ListView1)
    For $i=0 To $list_count-1
        _GUICtrlListView_SetItemSelected($ListView1,$i)
        $Read = _GUICtrlListView_GetItemTextArray($ListView1)
        FileWriteLine(@ScriptDir&'\Test.txt',$Read[1]&'|'&$Read[2]&'|'&$Read[3]&'|'&$Read[4])
    Next
EndFunc

Since my source code is so long, I cut it out for everyone to see. Has anyone ever made this mistake? Give me a fix because I use WM_NOTIFY to click on each item so it flashes very :(

Link to post
Share on other sites
  • Moderators

Loc,

No-one has replied because it is likely that no-one understands just what the problem actually is - that is certainly true in my case.

Posting just a small snippet of your script does not really help at all - you need to post a short runnable script which shows the problem so that we can firstly see what is happening and then offer possible solutions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

I save the listview item this way, but when I increase the value, it jumps to the last line. What I need here is when I save an item on a listview that it doesn't jump like that? What I don't know if it's :(

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

$Form1 = GUICreate("Form1", 615, 437, 359, 123)
$ListView = GUICtrlCreateListView("Column1|Column2|Column3|Column4", 16, 8, 577, 401)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
$hListView = GUICtrlGetHandle($ListView)
$ListView1_0 = GUICtrlCreateListViewItem("1|2|3|4", $ListView)
$ListView1_1 = GUICtrlCreateListViewItem("5|6|7|8", $ListView)
$ListView1_2 = GUICtrlCreateListViewItem("9|10|11|12", $ListView)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
    Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1)
    Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
    Local $hWndListView = $hListView
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
Case $hWndListView
Switch $iCode
    Case $NM_DBLCLK
        _SaveLoad()
EndSwitch
    EndSwitch
EndFunc

Func _SaveLoad()
    Local $vitrichon , $Value , $newsl , $settext
    $vitrichon = _GUICtrlListView_GetSelectedColumn($ListView)
    $settext = _GUICtrlListView_GetSelectedIndices($ListView)
    $Value = _GUICtrlListView_GetItemTextArray($ListView,$vitrichon)
        If $Value[1] <> '' Then
            $newsl = $Value[1] + 1
            $newmoney = _TrueValue($Value[2],$newsl)
            _GUICtrlListView_SetItemText($ListView, $settext,$newsl,0)
            _GUICtrlListView_SetItemText($ListView, $settext, $newmoney,2)
        EndIf
    _Save()
EndFunc

Func _Save()
    Local $filename = @ScriptDir & '\Test.txt'
    Local $hF = FileOpen($filename, 2)
        $list_count = _GUICtrlListView_GetItemCount ($ListView)
    For $i=0 To $list_count-1
        _GUICtrlListView_SetItemSelected($ListView,$i)
        $Read = _GUICtrlListView_GetItemTextArray($ListView)
        FileWriteLine($hF,$Read[1]&'|'&$Read[2]&'|'&$Read[3]&'|'&$Read[4])
    Next
    FileClose($hF)
EndFunc

Func _TrueValue($money, $sl = '0')
    Local $xldl, $kq
    If $sl = '0' Then
        $kq = StringReplace($money, ',', '')
    Else
        $xldl = StringReplace($money, ',', '')
        $kq = $xldl * $sl
    EndIf
    Return $kq
EndFunc

 

Link to post
Share on other sites
  • Moderators

Loc,

Do not select each line as you save it:

Func _Save()
    Local $filename = @ScriptDir & '\Test.txt'
    Local $hF = FileOpen($filename, 2)
    $list_count = _GUICtrlListView_GetItemCount($ListView)
    For $i = 0 To $list_count - 1
        ;_GUICtrlListView_SetItemSelected($ListView,$i) ; No need to select line <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $Read = _GUICtrlListView_GetItemTextArray($ListView, $i) ; Just use the line parameter <<<<<<<<<<<<<<<<<
        FileWriteLine($hF, $Read[1] & '|' & $Read[2] & '|' & $Read[3] & '|' & $Read[4])
    Next
    FileClose($hF)
EndFunc   ;==>_Save

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Moderators

Loc,

Every time I double click a line the file saved mirrors the altered ListView content - here is a modified script which displays the content of the file each time it is written:

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

$fSaved = False
Global $filename = @ScriptDir & '\Test.txt'

$Form1 = GUICreate("Form1", 615, 437, 359, 123)
$ListView = GUICtrlCreateListView("Column1|Column2|Column3|Column4", 16, 8, 577, 401)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
$hListView = GUICtrlGetHandle($ListView)
$ListView1_0 = GUICtrlCreateListViewItem("1|2|3|4", $ListView)
$ListView1_1 = GUICtrlCreateListViewItem("5|6|7|8", $ListView)
$ListView1_2 = GUICtrlCreateListViewItem("9|10|11|12", $ListView)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

    If $fSaved Then
        $aContent = FileReadToArray($filename)
        _ArrayDisplay($aContent, "", Default, 8)
        $fSaved = False
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
    Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1)
    Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
    Local $hWndListView = $hListView
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    _SaveLoad()

                    $fSaved = True

            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func _SaveLoad()
    Local $vitrichon, $Value, $newsl, $settext
    $vitrichon = _GUICtrlListView_GetSelectedColumn($ListView)
    $settext = _GUICtrlListView_GetSelectedIndices($ListView)
    $Value = _GUICtrlListView_GetItemTextArray($ListView, $vitrichon)
    If $Value[1] <> '' Then
        $newsl = $Value[1] + 1
        $newmoney = _TrueValue($Value[2], $newsl)
        _GUICtrlListView_SetItemText($ListView, $settext, $newsl, 0)
        _GUICtrlListView_SetItemText($ListView, $settext, $newmoney, 2)
    EndIf
    _Save()
EndFunc   ;==>_SaveLoad

Func _Save()

    Local $hF = FileOpen($filename, 2)
    $list_count = _GUICtrlListView_GetItemCount($ListView)
    For $i = 0 To $list_count - 1
        ;_GUICtrlListView_SetItemSelected($ListView,$i)
        $Read = _GUICtrlListView_GetItemTextArray($ListView, $i)
        FileWriteLine($hF, $Read[1] & '|' & $Read[2] & '|' & $Read[3] & '|' & $Read[4])
    Next
    FileClose($hF)
EndFunc   ;==>_Save

Func _TrueValue($money, $sl = '0')
    Local $xldl, $kq
    If $sl = '0' Then
        $kq = StringReplace($money, ',', '')
    Else
        $xldl = StringReplace($money, ',', '')
        $kq = $xldl * $sl
    EndIf
    Return $kq
EndFunc   ;==>_TrueValue

For me the file always matches the ListView content.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...