求教ListView右键编辑,无法获取表格里的信息也无法进行编辑(已解决)
本帖最后由 qsy666888 于 2018-3-12 14:05 编辑ListView右键编辑,无法获取表格里的信息也无法进行编辑,有大侠会的请指点一下啊,小弟在这里先谢谢了。 路过,需要学习 回复 1# qsy666888
试了几次,你看是这样吗?
#region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFYup")
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
xiugai($bj)
EndIf
EndSwitch
WEnd
Func WM_NOTIFYup($hWnd, $iMsg, $iwParam, $ilParam);弹出修改
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListBox, $tInfo
Local $iIndex
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex >= 0 Then xiugaia()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFYup
Func xiugaia()
xiugai(1)
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1, ""))
$Strnspin1 = StringSplit($Strn1, "|")
If $Strnspin1 = '0' Then
MsgBox(48, '提示', '请选择要修改的条目')
Else
$Strnspin1 = StringSplit($Strn1, "|")
If ($Strn1 = 0) Then
MsgBox(48, '提示', '不能修改!')
Else
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin1 = StringSplit($Strn1, "|")
GUICtrlSetData($Input1, '')
GUICtrlSetData($Date1, '')
GUICtrlSetData($Input2, '')
GUICtrlSetData($Combo1, '')
GUICtrlSetData($Date2, '')
$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 & " WHERE xh" & " = " & $Strnspin1) ;$t : 表示一个连接$adtables :表示的是这个表的名称
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
EndIf
EndIf
EndFunc ;==>xiugaia
Func xiugai($strID)
#region ### START Koda GUI section ### Form==========================================================修改框
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GForm2Close")
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, 130, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 130, 21)
Global $Combo1 = GUICtrlCreateInput("", 80, 106, 130, 21);, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
;GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
Global $Date2 = GUICtrlCreateInput("", 80, 129, 130, 21)
Global $Date1 = GUICtrlCreateInput(" ", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW, $Form2)
#endregion ### END Koda GUI section ###
EndFunc ;==>xiugai 回复 3# chzj589
"C:\Users\qinshiyong\Desktop\新建 AutoIt v3 脚本 (10).au3"(3,26) : warning: $WM_NOTIFY: 使用前并未进行声明.
GUIRegisterMsg($WM_NOTIFY,
~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\qinshiyong\Desktop\新建 AutoIt v3 脚本 (10).au3"(19,38) : warning: $GUI_EVENT_CLOSE: 使用前并未进行声明.
Case $GUI_EVENT_CLOSE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\qinshiyong\Desktop\新建 AutoIt v3 脚本 (10).au3"(36,44) : warning: $tagNMHDR: 使用前并未进行声明.
$tNMHDR = DllStructCreate($tagNMHDR,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\qinshiyong\Desktop\新建 AutoIt v3 脚本 (10).au3"(43,48) : warning: $NM_DBLCLK: 使用前并未进行声明.
Case $NM_DBLCLK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\qinshiyong\Desktop\新建 AutoIt v3 脚本 (10).au3"(45,84) : warning: $tagNMITEMACTIVATE: 使用前并未进行声明.
$tInfo = DllStructCreate($tagNMITEMACTIVATE, 本帖最后由 chzj589 于 2014-5-14 16:33 编辑
回复 4# qsy666888
我也是用你的 图书管理AU3代码改的,头文件图书管理AU3就有了
还是没有获取到ListView里面的信息 还是没有获取到ListView里面的信息
qsy666888 发表于 2014-5-14 16:41 http://www.autoitx.com/images/common/back.gif
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.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>
Global $Input1, $Input2, $Combo1, $Date1, $Date2, $ListView1, $Form2, $Form1
#region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFYup")
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
xiugai($bj)
EndIf
EndSwitch
WEnd
Func WM_NOTIFYup($hWnd, $iMsg, $iwParam, $ilParam);弹出修改
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListBox, $tInfo
Local $iIndex
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex >= 0 Then xiugaia()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFYup
Func xiugaia()
xiugai(1)
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1, ""))
$Strnspin1 = StringSplit($Strn1, "|")
If $Strnspin1 = '0' Then
MsgBox(48, '提示', '请选择要修改的条目')
Else
$Strnspin1 = StringSplit($Strn1, "|")
If ($Strn1 = 0) Then
MsgBox(48, '提示', '不能修改!')
Else
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin1 = StringSplit($Strn1, "|")
GUICtrlSetData($Input1, '')
GUICtrlSetData($Date1, '')
GUICtrlSetData($Input2, '')
GUICtrlSetData($Combo1, '')
GUICtrlSetData($Date2, '')
$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 & " WHERE xh" & " = " & $Strnspin1) ;$t : 表示一个连接 $adtables :表示的是这个表的名称
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
EndIf
EndIf
EndFunc ;==>xiugaia
Func xiugai($strID)
#region ### START Koda GUI section ### Form==========================================================修改框
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GForm2Close")
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, 130, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 130, 21)
Global $Combo1 = GUICtrlCreateInput("", 80, 106, 130, 21);, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
;GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
Global $Date2 = GUICtrlCreateInput("", 80, 129, 130, 21)
Global $Date1 = GUICtrlCreateInput(" ", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW, $Form2)
#endregion ### END Koda GUI section ###
EndFunc ;==>xiugai
Func GForm2Close()
GUISetState(@SW_HIDE, $Form2)
GUISetState(@SW_SHOW, $Form1)
EndFunc ;==>GForm2Close
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 能弹出信息框,但信息框里没有istView里的信息,是 空白的 回复 8# qsy666888
忘了说,是双击ListView1里的条目
右击是 Case $NM_RCLICK ; 右击
将 Case $NM_DBLCLK改为:Case $NM_RCLICK 嗯,不过关闭就退出了 回复 9# chzj589
谢谢你,看到了,但是一点关闭修改框全部就退出了,能改改吗 系统版本不同的原因吧。 回复 12# shqf
谢谢朋友的指点 回复 11# qsy666888
今天有事,等有空再改 好的,谢谢朋友
页:
[1]
2