【已解决】求助高手指点代码哦,写的代码,发现list不会自动出现
本帖最后由 fenhanxue 于 2012-10-23 23:37 编辑写了代码,运行后发现里面的list控件,不会自动显现,不知道为什么,如下图,求助高手哦
原始代码如下,谢谢亲了哦Dim $list,$RS1
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
;
$mdb_data_path=@ScriptDir&"\DB0.mdb"
$mdb_data_pwd="1"
$tblname="测试"
$tb=GUICreate("学习",300,400)
$ok=GUICtrlCreateButton("创建",5,5,50,50)
$du=GUICtrlCreateButton("读取",5,60,50,50)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
Case $du
du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
$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 name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
EndFunc
Func du(); 读取数据库
$i=0
$tab=GUICtrlCreateTab(60,10,200,20)
$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 * From "&$tblname )
while Not $RS.eof And Not $RS.bof
if @error =1 Then ExitLoop
GUICtrlCreateTabItem($RS.Fields(0).value)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;这里的$list[$i]为什么运行后不显示?
$list[$i]=GUICtrlCreateList($RS.Fields($i).value,62,120,200,200)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;这里的$list[$i]为什么运行后不显示?
$i=$i+1
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc 本帖最后由 邪恶海盗 于 2012-10-13 11:06 编辑
把创建的TAB标签和ListView放到While外面,While里面是向ListView写数据就好了... 回复 2# 邪恶海盗
谢谢亲哦,我尝试了下把list 和tabitem的创建写在while的外面,但是结果好像还是一样,list控件不会自动显现,不知道问题出在哪了哦?
这是我按照你说的修改后的代码:(就改了下一开始的dim的数量,和 自定义的 du()函数)Dim $list,$RS1,$tabitem
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
;
$mdb_data_path=@ScriptDir&"\DB0.mdb"
$mdb_data_pwd="1"
$tblname="测试"
$tb=GUICreate("学习",300,400)
$ok=GUICtrlCreateButton("创建",5,5,50,50)
$du=GUICtrlCreateButton("读取",5,60,50,50)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
Case $du
du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
$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 name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
EndFunc
Func du(); 读取数据库;;
$i=0
$tab=GUICtrlCreateTab(60,10,200,20)
$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 * From "&$tblname )
while Not $RS.eof And Not $RS.bof
if @error =1 Then ExitLoop
$i=$i+1
$RS.movenext
WEnd
$RS.close
$addfld.Close
For $j=1 To $i
$tabitem[$j]=GUICtrlCreateTabItem($j)
$list[$j]=GUICtrlCreateList($j,62,120,200,200)
Next
EndFunc 读取的函数里加上guictrlsetstate 楼主在While外面根本就没放ListView和Tab控件...
$tabitem[$j]=GUICtrlCreateTabItem($j)
$list[$j]=GUICtrlCreateList($j,62,120,200,200)
这两行才是创建ListView和Tab控件的... 回复 5# 邪恶海盗
这个倒问题不大,如果没猜错,楼主是想根据读取的情况创建不同数量的tabitem,关系不是太大,但必须要在创建后指定显示 回复 3# fenhanxue
$tblname="测试"
$tb=GUICreate("学习",300,400)
$ok=GUICtrlCreateButton("创建",5,5,50,50)
$du=GUICtrlCreateButton("读取",5,60,50,50)
du();读取显示
GUISetState() 应该是这样吧
Dim $list,$RS1,$tabitem
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
#include <GUIListView.au3>
Global $j
$mdb_data_path=@ScriptDir&"\DB0.mdb"
$mdb_data_pwd="1"
$tblname="测试"
$tb=GUICreate("学习",300,250)
$ok=GUICtrlCreateButton("创建",5,5,50,50)
$du=GUICtrlCreateButton("读取",5,60,50,50)
du();读取显示
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
;Case $du
;du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
GUICtrlSetData($tblname, 'name', 'name')
If FileExists($mdb_data_path) Then
MsgBox(64, "提示", "数据库已创建!")
Else
$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 name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
MsgBox(64, "提示", "创建成功!!")
EndIf
EndFunc
Func du(); 读取数据库;;
$i=0
$tab=GUICtrlCreateTab(60,10,220,20)
GUICtrlSendMsg($List, $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 * From "&$tblname )
while Not $RS.eof And Not $RS.bof
if @error =1 Then ExitLoop
$i=$i+1
GUICtrlCreateTabItem($RS.Fields(0).value )
$list[$i]=GUICtrlCreateList($RS.Fields(0).value& "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value,62,35,220,200, $LVS_EX_TRACKSELECT)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc
但是这样如何编辑??
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
$mdb_data_path = @ScriptDir & "\DB0.mdb"
$mdb_data_pwd = "1"
$tblname = "测试"
$tb = GUICreate("学习", 300, 250)
$ok = GUICtrlCreateButton("创建", 5, 5, 50, 50)
$du = GUICtrlCreateButton("读取", 5, 60, 50, 50)
$Tab1 = GUICtrlCreateTab(60, 0, 220, 20)
$TabSheet1 = GUICtrlCreateTabItem("1")
$ListView1 = GUICtrlCreateListView("姓名|性别|QQ", 60, 25, 220, 200, $LVS_REPORT, $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor(-1, 0xC0C0C0); 背景色
GUICtrlSetFont(-1, 10, 400, 0, "微软雅黑")
;GUICtrlSetColor(-1, 0x0000FF)
_GUICtrlListView_SetColumn($ListView1, 0, "姓名", 60, 2)
_GUICtrlListView_SetColumn($ListView1, 1, "性别", 60, 2)
_GUICtrlListView_SetColumn($ListView1, 2, "QQ", 80, 2)
$hImage = _GUIImageList_Create(1, 18);30为每行的间距(即网格高度)
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
du();读取显示
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
Case $du
du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
GUICtrlSetData($tblname, 'name', 'name')
If FileExists($mdb_data_path) Then
MsgBox(64, "提示", "数据库已创建!")
Else
$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 name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
MsgBox(64, "提示", "创建成功!!")
EndIf
EndFunc ;==>jian
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 * 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, $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc ;==>du 好多个出去玩了,一直不在线,不好意思哦,看看看看~ 回复 4# netegg
哇,蛋GG果然高手啊,加了个guictrlsetstate,瞬间解决问题拉~谢谢谢谢~ 回复 5# 邪恶海盗
明白亲的意思拉,亲的意思是在一开始的while外面创建控件,
我理解成是在du()这个函数里面,还有个while,我理解成是在du()里面的while外面创建控件了,好尴尬拉,终于明白拉,谢谢亲呢 回复 8# chzj589
加个guictrlsetstate解决拉,谢谢亲呢~
页:
[1]