liuyilun 发表于 2017-2-7 18:04:17

两个Listview内容互通的问题[已解决]

本帖最后由 liuyilun 于 2017-2-8 16:25 编辑

我想实现的是点击左边的文件会在右边的Listview中显示
但有个BUG是左边已点击过项再点击还会继续在右边添加,导致我最后打开的时候会打开多个同名文件,这个该怎么修改呢?
最好可以实现点击左边的添加至右边,点击右边删除选中项
我有试过点击后删除所选项,但是这导致点击右边的项也会继续添加#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include-once

$Dir = "C:\Users\Administrator\Desktop\目录\"
$Filelist = _FileListToArrayRec($Dir, "*.txt;*.xml", 1, 1, 0, 1)
Local $Item1[$Filelist], $Item2
GUICreate("文件选择", 720, 500)
$ListView1 = GUICtrlCreateListView("文件目录", 20, 30, 300, 400)
For $i = 0 To $Filelist - 1
        $Item1[$i] = GUICtrlCreateListViewItem($Filelist[$i + 1], $ListView1)
Next
$ListView2 = GUICtrlCreateListView("文件目录", 400, 30, 300, 400)
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView2, 0, $LVSCW_AUTOSIZE_USEHEADER)
$Button1 = GUICtrlCreateButton("打开", 335, 190, 50)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Item1 To $Item1[$Filelist - 1]
                        ReDim $Item2
                        $Item2 = GUICtrlCreateListViewItem(GUICtrlRead($nMsg), $ListView2)
                Case $Button1
                        For $i = 0 To UBound($Item2) - 1
                                Run("notepad.exe " & $Dir & StringTrimRight(GUICtrlRead($Item2[$i]), 1))
                        Next
                        Exit
        EndSwitch
WEnd

hualong1009 发表于 2017-2-7 19:12:44

顶你,{:face (114):}

hualong1009 发表于 2017-2-7 19:12:49

顶你,{:face (114):}

zghwelcome 发表于 2017-2-8 11:07:00

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include-once

$Dir = "C:\Documents and Settings\Administrator\My Documents\"
$Filelist = _FileListToArrayRec($Dir, "*.txt;*.xml", 1, 1, 0, 1)
Local $Item1[$Filelist], $Item2
GUICreate("文件选择", 720, 500)
$ListView1 = GUICtrlCreateListView("文件目录", 20, 30, 300, 400)
For $i = 0 To $Filelist - 1
        $Item1[$i] = GUICtrlCreateListViewItem($Filelist[$i + 1], $ListView1)
Next
$ListView2 = GUICtrlCreateListView("文件目录", 400, 30, 300, 400)
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView2, 0, $LVSCW_AUTOSIZE_USEHEADER)
$Button1 = GUICtrlCreateButton("打开", 335, 190, 50)
GUISetState()
Global $str = '' ;//总字符串
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Item1 To $Item1[$Filelist - 1]
                        If Not StringInStr($str, GUICtrlRead($nMsg)) Then
                                $str &= GUICtrlRead($nMsg) ;//累计字符串
                                ReDim $Item2
                                $Item2 = GUICtrlCreateListViewItem(GUICtrlRead($nMsg), $ListView2)
                        EndIf
                Case $Button1
                        For $i = 0 To UBound($Item2) - 1
                                Run("notepad.exe " & $Dir & StringTrimRight(GUICtrlRead($Item2[$i]), 1))
                        Next
                        Exit
        EndSwitch
WEnd
也许有更好的方案

liuyilun 发表于 2017-2-8 12:11:41

回复 4# zghwelcome


    感谢,测试成功,我去研究一下点击右边删除选中项的功能
页: [1]
查看完整版本: 两个Listview内容互通的问题[已解决]