找回密码
 加入
搜索
楼主: qsy666888

[GUI管理] 求教ListView右键编辑,无法获取表格里的信息也无法进行编辑(已解决)

 火.. [复制链接]
发表于 2014-5-14 18:33:25 | 显示全部楼层
回复 15# qsy666888
查看短信
发表于 2014-5-14 20:28:49 | 显示全部楼层
回复 15# qsy666888

给你一个例子.
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
Global $ListView1 = GUICtrlCreateListView("序号|图书名称|借出时间|学生姓名|班级|归还时间", 0, 0, 617, 289)
Local $buttoncontext = GUICtrlCreateContextMenu($ListView1)
Local $tj = GUICtrlCreateMenuItem("添加信息...", $buttoncontext)
Local $bj = GUICtrlCreateMenuItem("编辑信息...", $buttoncontext)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$mdb_data_path = @ScriptDir & "\msq.mdb"
$mdb_data_pwd = ""
$T = "*"
$tblname = "mydb"
new()
If FileExists($mdb_data_path) Then du()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $bj
                        Local $n_id = _GUICtrlListView_GetItemText($ListView1, Number(_GUICtrlListView_GetSelectedIndices($ListView1)));选中行的第一列
                        If $n_id = 0 Then
                                MsgBox(48, '提示:', '请选择要修改的条目!')
                        Else
                                ; 这里添加 ---------------------------
                                Local $sText = _GUICtrlListView_GetItemTextString($ListView1, $n_id - 1)
                                Local $string = StringSplit($sText, '|')
                                ;------------------------------------
                                xiugai($string); $string
                        EndIf
        EndSwitch
WEnd

Func xiugai($strID)
        #Region ### START Koda GUI section ### Form==========================================================修改框
;~         Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
        Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1, -1, -1, $Form1) ;这样比较好
        Global $Label1 = GUICtrlCreateLabel("图书名称:", 16, 37, 64, 17)
        Global $Label2 = GUICtrlCreateLabel("借出时间:", 16, 61, 64, 17)
        Global $Label3 = GUICtrlCreateLabel("学    生:", 16, 81, 64, 17)
        Global $Label4 = GUICtrlCreateLabel("年级(班):", 16, 109, 64, 17)
        Global $Label5 = GUICtrlCreateLabel("归还时间:", 14, 133, 64, 17)
        Global $Button1 = GUICtrlCreateButton("修    改", 240, 160, 64, 25)
        Global $Group1 = GUICtrlCreateGroup("图书管理信息编辑", 8, 3, 305, 193)
        Global $Input1 = GUICtrlCreateInput("", 80, 33, 217, 21)
        Global $Input2 = GUICtrlCreateInput("", 80, 81, 217, 21)
        Global $Combo1 = GUICtrlCreateCombo("", 80, 106, 129, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
        GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
        Global $Date2 = GUICtrlCreateDate("", 80, 129, 130, 21)
        Global $Date1 = GUICtrlCreateDate(" ", 80, 56, 130, 21)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        
        ; 这里添加 ---------------------------
        GUICtrlSetData($Input1, $strID[2])
        GUICtrlSetData($Date1, StringTrimRight(StringRegExpReplace(StringRegExpReplace($strID[3], "[年月日]", "/"), "(?<=/)(\d)(?=/|$)", "0\1"), 1))
        GUICtrlSetData($Input2, $strID[4])
        GUICtrlSetData($Combo1, $strID[5])
        GUICtrlSetData($Date2, StringTrimRight(StringRegExpReplace(StringRegExpReplace($strID[6], "[年月日]", "/"), "(?<=/)(\d)(?=/|$)", "0\1"), 1))
        ;------------------------------------
        
        GUISetState(@SW_SHOW)
        #EndRegion ### END Koda GUI section ###

        While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                GUIDelete($Form2)
                                ExitLoop
                        Case $Button1
                                ;xie()
                EndSwitch
        WEnd
EndFunc   ;==>xiugai

Func new()
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $newMdb.ActiveConnection.Close
        $addtbl = ObjCreate("ADODB.Connection")
        $addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addtbl.Execute("CREATE TABLE " & $tblname)
        $addtbl.Close;
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addfld.Execute("ALTER TABLE " & $tblname & " ADD xh identity(1, 1) primary key,tsmc text(255) ,jcsj text(80),xsxm text(100),bj text(50),ghsj text(50)");id identity(1, 1) primary key为自动编号和主键
        $addfld.Close
EndFunc   ;==>new

Func du()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $tblname)
        While Not $RS.eof And Not $RS.bof
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value & "|" & $RS.Fields(4).value & "|" & $RS.Fields(5).value, $ListView1)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
EndFunc   ;==>du

Func _clearInput()
        GUICtrlSetData($Input1, '')
        GUICtrlSetData($Date1, '')
        GUICtrlSetData($Input2, '')
        GUICtrlSetData($Combo1, '')
        GUICtrlSetData($Date2, '')
        GUICtrlSetState($Input1, $GUI_FOCUS)
EndFunc   ;==>_clearInput

Func _setInput($strID)
        Dim $addfld, $RS
        $addtbl = ObjCreate("ADODB.Connection")
        $addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate('ADOX.Catalog')
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $tblname & " WHERE 序号" & " = " & $strID)
        $id = $RS.Fields(0).value
        GUICtrlSetData($Input1, $RS.Fields(1).value)
        GUICtrlSetData($Date1, $RS.Fields(2).value)
        GUICtrlSetData($Input2, $RS.Fields(3).value)
        GUICtrlSetData($Combo1, $RS.Fields(4).value)
        GUICtrlSetData($Date2, $RS.Fields(5).value)
        $RS.movenext
        $RS.close
        $addfld.Close
EndFunc   ;==>_setInput
发表于 2014-5-15 10:05:43 | 显示全部楼层
不知道我这样的可不可以
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
Global $ListView1 = GUICtrlCreateListView("序号|图书名称|借出时间|学生姓名|班级|归还时间", 0, 0, 617, 289,BitOR($LVS_SINGLESEL, $LVS_SORTASCENDING))
Local $buttoncontext = GUICtrlCreateContextMenu($ListView1)
Local $tj = GUICtrlCreateMenuItem("添加信息...", $buttoncontext)
Local $bj = GUICtrlCreateMenuItem("编辑信息...", $buttoncontext)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$mdb_data_path=@ScriptDir&"\msq.mdb"
   $mdb_data_pwd=""
   $T="*"
   $tblname="mydb"
   new()
   If FileExists($mdb_data_path) Then du()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $bj
                        Local $n_id = _GUICtrlListView_GetItemText($ListView1, Number( _GUICtrlListView_GetSelectedIndices($ListView1)));选中行的第一列
                                If $n_id = 0 Then
                                        MsgBox(48, '提示:', '请选择要修改的条目!')
                                Else
                                        xiugai($bj)
                                EndIf
                
        EndSwitch
WEnd
Func xiugai($strID)
#Region ### START Koda GUI section ### Form==========================================================修改框
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
Global $Label1 = GUICtrlCreateLabel("图书名称:", 16, 37, 64, 17)
Global $Label2 = GUICtrlCreateLabel("借出时间:", 16, 61, 64, 17)
Global $Label3 = GUICtrlCreateLabel("学    生:", 16, 81, 64, 17)
Global $Label4 = GUICtrlCreateLabel("年级(班):", 16, 109, 64, 17)
Global $Label5 = GUICtrlCreateLabel("归还时间:", 14, 133, 64, 17)
Global $Button1 = GUICtrlCreateButton("修    改", 240, 160, 64, 25)
Global $Group1 = GUICtrlCreateGroup("图书管理信息编辑", 8, 3, 305, 193)
Global $Input1 = GUICtrlCreateInput("", 80, 33, 217, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 217, 21)
Global $Combo1 = GUICtrlCreateCombo("", 80, 106, 129, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
Global $Date2 = GUICtrlCreateDate("", 80, 129, 130, 21)
Global $Date1 = GUICtrlCreateDate(" ", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_du2()
While 1
        $nMsg = GUIGetMsg()        
        Switch $nMsg                
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form2)
                                ExitLoop
                Case $bj

        EndSwitch
        
WEnd
EndFunc

Func new()
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $newmdb.ActiveConnection.Close
        $addtbl = ObjCreate("ADODB.Connection")
        $addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addTbl.Execute("CREATE TABLE " & $tblname)
        $addtbl.Close;
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addfld.Execute("ALTER TABLE " & $tblname & " ADD xh identity(1, 1) primary key,tsmc text(255) ,jcsj text(80),xsxm text(100),bj text(50),ghsj text(50)");id identity(1, 1) primary key为自动编号和主键
        $addfld.Close
   EndFunc

Func du()
     GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
          $addfld = ObjCreate("ADODB.Connection")
            $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path& ";Jet Oledb:Database Password=" & $mdb_data_pwd)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select "&$T & " From " & $tblname )
           while Not $RS.eof And Not $RS.bof
           if @error =1 Then ExitLoop
            GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value&"|"& $RS.Fields (5).value,$ListView1 )
             $rs.movenext
              WEnd
               $rs.close
              $addfld.Close      
EndFunc    

 Func _clearInput()
                   GUICtrlSetData($Input1, '')
                   GUICtrlSetData($Date1, '')
                   GUICtrlSetData($Input2, '')
                   GUICtrlSetData($Combo1, '')
                   GUICtrlSetData($Date2, '')        
                   GUICtrlSetState($Input1, $GUI_FOCUS)
   EndFunc  
           
   Func _setInput($strID)
                   Dim $addfld, $RS
                   $addtbl = ObjCreate("ADODB.Connection")
        $addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                   $RS = ObjCreate('ADODB.Recordset')
                   $RS.ActiveConnection = $addfld
                   $RS.Open("Select " & $T & " From " & $tblname & " WHERE xh" & " = " & $strID)
                   GUICtrlSetData($Input1, $RS.Fields(1).value)
                   GUICtrlSetData($Date1, $RS.Fields(2).value)
                   GUICtrlSetData($Input2, $RS.Fields(3).value)
                   GUICtrlSetData($Combo1, $RS.Fields(4).value)
                   GUICtrlSetData($Date2, $RS.Fields(5).value)
                   $RS.close
                   $addfld.Close
           EndFunc   

Func _du2()
            $a = GUICtrlRead(GUICtrlRead($ListView1))
                $b = StringSplit($a,"|")
                For $i = 1 to $b[0]

            Next        
            GUICtrlSetData($Input1, $b[2])        
                GUICtrlSetData($Date1, $b[3])
            GUICtrlSetData($Input2, $b[4])
            GUICtrlSetData($Combo1, $b[5])
            GUICtrlSetData($Date2, $b[6])
EndFunc
 楼主| 发表于 2014-5-15 11:20:36 | 显示全部楼层
回复 18# 没有知道


    可以i,不过在空白地方操作的时候闪退
发表于 2014-5-15 17:13:08 | 显示全部楼层
本帖最后由 没有知道 于 2014-5-15 17:31 编辑
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
Global $ListView1 = GUICtrlCreateListView("序号|图书名称|借出时间|学生姓名|班级|归还时间", 0, 0, 617, 289,BitOR($LVS_SINGLESEL, $LVS_SORTASCENDING))
Local $buttoncontext = GUICtrlCreateContextMenu($ListView1)
Local $tj = GUICtrlCreateMenuItem("添加信息...", $buttoncontext)
Local $bj = GUICtrlCreateMenuItem("编辑信息...", $buttoncontext)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$mdb_data_path=@ScriptDir&"\msq.mdb"
   $mdb_data_pwd=""
   $T="*"
   $tblname="mydb"
   new()
   If FileExists($mdb_data_path) Then du()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $bj
                        Local $n_id = _GUICtrlListView_GetItemText($ListView1, Number( _GUICtrlListView_GetSelectedIndices($ListView1)));选中行的第一列
                                If $n_id = 0 Then
                                        MsgBox(48, '提示:', '请选择要修改的条目!')
                                Else
                                        xiugai($bj)
                                EndIf
                
        EndSwitch
WEnd
Func xiugai($strID)
#Region ### START Koda GUI section ### Form==========================================================修改框
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
Global $Label1 = GUICtrlCreateLabel("图书名称:", 16, 37, 64, 17)
Global $Label2 = GUICtrlCreateLabel("借出时间:", 16, 61, 64, 17)
Global $Label3 = GUICtrlCreateLabel("学    生:", 16, 81, 64, 17)
Global $Label4 = GUICtrlCreateLabel("年级(班):", 16, 109, 64, 17)
Global $Label5 = GUICtrlCreateLabel("归还时间:", 14, 133, 64, 17)
Global $Button1 = GUICtrlCreateButton("修    改", 240, 160, 64, 25)
Global $Group1 = GUICtrlCreateGroup("图书管理信息编辑", 8, 3, 305, 193)
Global $Input1 = GUICtrlCreateInput("", 80, 33, 217, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 217, 21)
Global $Combo1 = GUICtrlCreateCombo("", 80, 106, 129, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
;Global $Date2 = GUICtrlCreateDate("", 80, 129, 130, 21)
Global $Date2 = GUICtrlCreateInput("", 80, 129, 130, 21)
;Global $Date1 = GUICtrlCreateDate("", 80, 56, 130, 21)
Global $Date1 = GUICtrlCreateInput("", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$a = GUICtrlRead(GUICtrlRead($ListView1))
If $a = "" Then 
        MsgBox(0,0,"没有选中数据")
Else
        _du2($a)
EndIf


While 1
        $nMsg = GUIGetMsg()        
        Switch $nMsg                
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form2)
                        GUISetState(@SW_SHOW,$Form2)
            GUISetState(@SW_ENABLE,$Form2)
                        ExitLoop
                Case $a

        EndSwitch
        
WEnd
EndFunc

Func new()
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $newmdb.ActiveConnection.Close
        $addtbl = ObjCreate("ADODB.Connection")
        $addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addTbl.Execute("CREATE TABLE " & $tblname)
        $addtbl.Close;
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addfld.Execute("ALTER TABLE " & $tblname & " ADD xh identity(1, 1) primary key,tsmc text(255) ,jcsj text(80),xsxm text(100),bj text(50),ghsj text(50)");id identity(1, 1) primary key为自动编号和主键
        $addfld.Close
   EndFunc

Func du()
     GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
          $addfld = ObjCreate("ADODB.Connection")
            $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path& ";Jet Oledb:Database Password=" & $mdb_data_pwd)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select "&$T & " From " & $tblname )
           while Not $RS.eof And Not $RS.bof
           if @error =1 Then ExitLoop
            GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value&"|"& $RS.Fields (5).value,$ListView1 )
             $rs.movenext
              WEnd
               $rs.close
              $addfld.Close      
EndFunc    
 
Func _du2($a)
                $b = StringSplit($a,"|")
                For $i = 1 to $b[0]
                Next
                GUICtrlSetData($Input1, $b[2])        
                GUICtrlSetData($Date1, $b[3])
            GUICtrlSetData($Input2, $b[4])
            GUICtrlSetData($Combo1, $b[5])
            GUICtrlSetData($Date2, $b[6])
EndFunc
那就改成这样试试
 楼主| 发表于 2014-5-15 17:53:01 | 显示全部楼层
谢谢大家对我的帮助,非常感谢
发表于 2014-5-16 09:15:39 | 显示全部楼层
感谢,,不过为什么要仅作者可见?
发表于 2014-5-16 17:06:56 | 显示全部楼层
nmd,最烦仅作者可见
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 21:32 , Processed in 1.312126 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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