找回密码
 加入
搜索
查看: 5753|回复: 13

[GUI管理] 【已解决】请看下我这代码,从listview中读取数据总是失败

  [复制链接]
发表于 2012-12-2 10:43:56 | 显示全部楼层 |阅读模式
本帖最后由 9800se 于 2012-12-2 18:20 编辑

这段代码运行时截图:


想达到的最终目的:
点击“萧跃”,再点击“04|小乐”这行,最后点击“确认”,弹出窗口显示“04”或者“4”,且得到的这个数据应该是数字类型的,因为还有后用。
已经整一天想这个了,头痛,只能来这求助。
先谢了!

代码如下:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <SliderConstants.au3>
#include <GuiListView.au3>

Opt("wintitlematchmode",2)
Opt("mousecoordmode",2)

Global $x ;方式选择
Global $z ;根据$x的值确定自己
Global $y=465 ;垂直方向坐标
Global $wincreated
Global $p,$n

_Kuangjia();人机界面

Func _Kuangjia();人机界面
  Local $treeview,$item1,$item2,$shuomin,$xiaoyue,$shenghe
  Local $startlabel,$shuomin_label,$xiaoyue_ListView,$shenghe_ListView
  Local $gotobutton,$cancelbutton
  Local $msg,$item,$text
  $font="楷体_GB2312"
  
  $wincreated = GUICreate("",275,220)


  $treeview = GUICtrlCreateTreeView(5, 27, 139, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
  $item1 = GUICtrlCreateTreeViewItem("Item_1", $treeview)
  GUICtrlSetColor(-1, 0x0000C0)
  $item2 = GUICtrlCreateTreeViewItem("Item_2", $treeview)
  GUICtrlSetColor(-1, 0x0000C0)
  $shuomin = GUICtrlCreateTreeViewItem("说明", $item1)
  GUICtrlSetColor(-1, 0xff0000)
  $xiaoyue = GUICtrlCreateTreeViewItem("萧跃", $item1)
  $shenghe = GUICtrlCreateTreeViewItem("沈河", $item1)


  $startlabel = GUICtrlCreateLabel("startlabel", 150, 35, 120, 95)
  GUICtrlSetFont(-1,12,800,0,$font)
  GUICtrlSetColor(-1,0xff0000)

  $shuomin_label = GUICtrlCreateLabel("shuomin_label", 155, 45, 110, 95)
  GUICtrlSetFont(-1,10,400)
  GUICtrlSetColor(-1,0xff0000)
  GUICtrlSetState(-1, $GUI_HIDE)

  
  $xiaoyue_ListView = GUICtrlCreateListView("", 150, 27, 120, 110)
    _GUICtrlListView_AddColumn($xiaoyue_ListView, "No", 30,2)
    _GUICtrlListView_AddColumn($xiaoyue_ListView, "人员", 60)
    GUICtrlCreateListViewItem("01|小华", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("02|小强", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("03|小贤", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("04|小乐", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("05|老龙", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("06|老军", $xiaoyue_ListView)
    GUICtrlCreateListViewItem("07|大熊", $xiaoyue_ListView)
  GUICtrlSetState($xiaoyue_ListView, $GUI_HIDE) 

  $shenghe_ListView = GUICtrlCreateLabel("沈河", 155, 55, 110, 50)
  GUICtrlSetFont(-1,15,800,0,$font)
  GUICtrlSetColor(-1,0xff0000)
  GUICtrlSetState(-1, $GUI_HIDE)


  GUICtrlCreateLabel("",150, 28, 120, 2, $SS_SUNKEN)
  GUICtrlCreateLabel("",150, 136, 120, 2, $SS_SUNKEN)

  $gotobutton = GUICtrlCreateButton("确定",150, 143, 57, 20)
  $cancelbutton = GUICtrlCreateButton("取消",213, 143, 57, 20)

; 默认展开并加粗
  GUICtrlSetState($item1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) 
  GUICtrlSetState($item2, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) 

  GUISetState()

  While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
        ExitLoop
      Case $msg = $item1
        $x=0
        GUIChangeItems($shuomin_label,$xiaoyue_ListView,$shenghe_ListView,$startlabel,$startlabel)
      Case $msg = $item2
        $x=0
        GUIChangeItems($shuomin_label,$xiaoyue_ListView,$shenghe_ListView,$startlabel,$startlabel)
      Case $msg = $shuomin
        $x=0
        GUIChangeItems($startlabel,$xiaoyue_ListView,$shenghe_ListView,$shuomin_label,$shuomin_label)

      Case $msg = $xiaoyue
        $x=1
        GUIChangeItems($startlabel,$shuomin_label,$shenghe_ListView,$xiaoyue_ListView,$xiaoyue_ListView)

      Case $msg = $xiaoyue_ListView
        $x=3
        $p = GUICtrlRead(GUICtrlRead($xiaoyue_ListView))
        
      
        
        
        
      Case $msg = $shenghe
        $x=2
        GUIChangeItems($startlabel,$shuomin_label,$xiaoyue_ListView,$shenghe_ListView,$shenghe_ListView)
      Case $msg = $gotobutton
        If $x = 0 Then
          MsgBox(0, "", "错误")
          Exit
        Else
          GUISetState(@SW_HIDE,$wincreated)
          _star()
        EndIf
      EndSelect
  WEnd
EndFunc  

Func GUIChangeItems($hide1, $hide2, $hide3,$show1, $show2)
  Local $idx
  For $idx = $hide1 To $hide3
    GUICtrlSetState($idx, $GUI_HIDE)
  Next
  For $idx = $show1 To $show2
    GUICtrlSetState($idx, $GUI_SHOW)
  Next
EndFunc



;选择动作方式
Func _star()
  Select
    Case $x=1
      MsgBox(0,"","萧跃")
    Case $x=2
      MsgBox(0,"","沈河")
    Case $x=3
      MsgBox(0,"",$p)
  EndSelect
  Exit
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-12-2 12:09:52 | 显示全部楼层
回复 1# 9800se

楼主你写的都是些什么跟什么啊??
发表于 2012-12-2 12:19:38 | 显示全部楼层
回复 2# annybaby
说白了就是没切换操作句柄罢了,懒得回答,example文件里有实例
 楼主| 发表于 2012-12-2 12:19:53 | 显示全部楼层
回复 2# annybaby


    呃很难懂吗?我再把标题改下,不行就试试运行一下,配合红色的说明字体应该不会有什么问题了吧。
 楼主| 发表于 2012-12-2 12:34:52 | 显示全部楼层
回复 3# netegg


    已经试过多种办法,看了不少实例,结果还是不行才放上来求助的。
也许你觉得简单,但我偏偏就不知道或者没想到,请指点一下!
发表于 2012-12-2 12:48:33 | 显示全部楼层
回复 5# 9800se


   其实就是操作LISTVIEW的问题.

star 函数里对应地方改为:
        Case $x=1
                $index = _GUICtrlListView_GetSelectedIndices($hLv)
                MsgBox(0,"",_GUICtrlListView_GetItemText($hLv, $index))

$hLv 需要在程序前头声明为 Global
创建 $xiaoyue_ListView 后, 获取对应的控件句柄:
$hLv = GUICtrlGetHandle(-1)

评分

参与人数 1金钱 +20 收起 理由
9800se + 20 我很赞同

查看全部评分

发表于 2012-12-2 12:51:15 | 显示全部楼层
回复 4# 9800se

看你的代码真的会头晕~~~所以不敢细看
把$xiaoyue_ListView 定义成全局变量,然后
把你要显示的信息
      MsgBox(0,"","萧跃")

改成
ControlListView($wincreated,'',$xiaoyue_ListView,'GetSelected')+1
   

即可

其它的没细看,真的非常混乱`
发表于 2012-12-2 12:52:55 | 显示全部楼层
首先应该将变量放在函数声明外面,如:将第22行移到第17行。
将139行改为
MsgBox(0, '', Number(_GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($xiaoyue_ListView)) + 1))
发表于 2012-12-2 12:56:41 | 显示全部楼层
另外,LZ的代码需要好好设计和组织下,还有,如果ListView等其余控件数据量不大,完全不必要每个为独立的ListView,只需一个,再该控件内更新数据即可。不用那么多的显隐控件操作。
发表于 2012-12-2 13:05:40 | 显示全部楼层
C:\Program Files\autoit3\Examples\GUI\Advanced\treeview.au3
自己去看
这不是简单不简单的事,是用心不用心的事
发表于 2012-12-2 13:17:35 | 显示全部楼层
另外还有
$msg = $item1时For $idx = $hide1 To $hide3试过$hide1,$hide3都是多少吗,如果没错的话,我这一个是13,一个是19,不知道中间的索引有没有东西
$msg = $item2时结果一样
$msg = 其他项目时根本就没上下限
发表于 2012-12-2 14:03:33 | 显示全部楼层
_GUICtrlListView_GetSelectedIndices库的问题,由于设计的返回值不一定是单一选中,所以数字字符就分的不是特别清楚,number下就好了
 楼主| 发表于 2012-12-2 18:19:09 | 显示全部楼层
问题已经解决了,谢谢各位热心的兄弟!
本人只是野路子半路出家,只是为了工作偷懒才找到autoit,这也是第一次发贴,可以说我甚至连菜鸟都算不上,呵呵,请各路高手多多体谅了,方法我只试了user3000的,因为其他的看不懂啊,不管了,反正能抓老鼠就行!
发表于 2012-12-2 21:23:22 | 显示全部楼层
回复 13# 9800se


    呵,你这么说,楼上几位大能会很没面子的.
真想学AU3,必须认真看一看他们的建议的.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 10:30 , Processed in 0.086665 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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