找回密码
 加入
搜索
查看: 1928|回复: 4

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

[复制链接]
发表于 2017-2-7 18:04:17 | 显示全部楼层 |阅读模式
本帖最后由 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[0]], $Item2[0]
GUICreate("文件选择", 720, 500)
$ListView1 = GUICtrlCreateListView("文件目录", 20, 30, 300, 400)
For $i = 0 To $Filelist[0] - 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[0] To $Item1[$Filelist[0] - 1]
                        ReDim $Item2[UBound($Item2) + 1]
                        $Item2[UBound($Item2) - 1] = 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
发表于 2017-2-7 19:12:44 | 显示全部楼层
顶你,
发表于 2017-2-7 19:12:49 | 显示全部楼层
顶你,
发表于 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[0]], $Item2[0]
GUICreate("文件选择", 720, 500)
$ListView1 = GUICtrlCreateListView("文件目录", 20, 30, 300, 400)
For $i = 0 To $Filelist[0] - 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[0] To $Item1[$Filelist[0] - 1]
                        If Not StringInStr($str, GUICtrlRead($nMsg)) Then
                                $str &= GUICtrlRead($nMsg) ;//累计字符串
                                ReDim $Item2[UBound($Item2) + 1]
                                $Item2[UBound($Item2) - 1] = 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
也许有更好的方案
 楼主| 发表于 2017-2-8 12:11:41 | 显示全部楼层
回复 4# zghwelcome


    感谢,测试成功,我去研究一下点击右边删除选中项的功能
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-25 11:05 , Processed in 0.078667 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表