请问一个关于ListView的问题!
主界面中创建一个 ListView1,使用 Func _List1() 来读取数据库资料并创建 ListViewItems,之后在主界面中点击按钮打开另一界面,另一界面中再一个 ListView2,使用 Func_List2() 来读取数据库资料并创建 ListViewItems
问题在:主界面中的 ListView1 可以成功读取数据库资料,但另一界面中的 ListView2 一按按钮就出错了!!
出错行数:42 行 _GUICtrlListView_DeleteAllItems($ListView2) 的位置,每次都是提示这个出错,不知道什么原因??
代码如下:
Func _ListView2()
$ListView2_GUI = GUICreate("ListView2", 570, 294, -1, -1)
$ListView2 = GUICtrlCreateListView("", 8, 8, 554, 278)
_GUICtrlListView_AddColumn($ListView2, "1", 30, 2)
_GUICtrlListView_AddColumn($ListView2, "2", 80, 2)
_GUICtrlListView_AddColumn($ListView2, "3", 80, 2)
_GUICtrlListView_AddColumn($ListView2, "4", 140, 2)
_GUICtrlListView_AddColumn($ListView2, "5", 140, 2)
_GUICtrlListView_AddColumn($ListView2, "6", 80, 0)
GUICtrlSendMsg($ListView2, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
_GUICtrlListView_RegisterSortCallBack($ListView2)
GUISetState(@SW_SHOW)
_List2()
While 1
............
WEnd
_GUICtrlListView_UnRegisterSortCallBack($ListView2)
EndFunc
Func _ListView1()
$ListView1_GUI = GUICreate("ListView1", 570, 294, -1, -1)
$ListView1 = GUICtrlCreateListView("", 8, 8, 554, 278)
_GUICtrlListView_AddColumn($ListView1, "1", 30, 2)
_GUICtrlListView_AddColumn($ListView1, "2", 80, 2)
_GUICtrlListView_AddColumn($ListView1, "3", 80, 2)
_GUICtrlListView_AddColumn($ListView1, "4", 140, 2)
_GUICtrlListView_AddColumn($ListView1, "5", 140, 2)
_GUICtrlListView_AddColumn($ListView1, "6", 80, 0)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
_GUICtrlListView_RegisterSortCallBack($ListView1)
GUISetState(@SW_SHOW)
_List1()
While 1
............
WEnd
_GUICtrlListView_UnRegisterSortCallBack($ListView1)
EndFunc
Func _List2()
_GUICtrlListView_DeleteAllItems($ListView2)
$Conn = ObjCreate("ADODB.Connection")
$Rs = ObjCreate("ADODB.Recordset")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $Path & ";Jet Oledb:Database Password=" & $PWD)
$Rs.ActiveConnection = $Conn
$Rs.Open("Select * From Admin")
While (Not $Rs.eof And Not $Rs.bof)
............
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, $ListView2)
$Rs.Movenext
WEnd
$Rs.Close
$Conn.Close
EndFunc
Func _List1()
_GUICtrlListView_DeleteAllItems($ListView1)
$Conn = ObjCreate("ADODB.Connection")
$Rs = ObjCreate("ADODB.Recordset")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $Path & ";Jet Oledb:Database Password=" & $PWD)
$Rs.ActiveConnection = $Conn
$Rs.Open("Select * From User")
While (Not $Rs.eof And Not $Rs.bof)
............
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
$Conn.Close
EndFunc
[ 本帖最后由 eddielove 于 2009-4-19 14:26 编辑 ] 请提供完整代码。。。。。 试试前面加上一行 Global$ListView2 感谢 PCBar,问题已解决!谢谢
页:
[1]