找回密码
 加入
搜索
查看: 2431|回复: 5

[AU3基础] 怎么读取LISTVIEW指定字段。算出总数[已解决]

  [复制链接]
发表于 2011-8-9 19:42:28 | 显示全部楼层 |阅读模式
本帖最后由 udbghdto 于 2011-8-10 10:26 编辑

怎么读取LISTVIEW指定字段。算出总数。。不是数据库字段。

LISTVIEW数值从数据库读取。然后读取LISTVIEW指定字段算出总价。
因为要用到查询功能。LISTVIEW数量不固定。就不能直接数据库读取。

数据库文件。
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$mdb = @ScriptDir & "\db1.mdb"
$Table = "db1"
$T = "*"

$Form1_1 = GUICreate("Form1", 880, 442, 183, 114)
$ListView1 = GUICtrlCreateListView("编号 |品名|类型|数量|单价|总价|经办人|单位或个人|货款|日期", 56, 24, 673, 297)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 60)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 50)
$Label1 = GUICtrlCreateLabel("合计:元", 64, 344, 84, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

dumdb()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func dumdb()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $Table)
        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 & "|" & $RS.Fields(6).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(8).value & "|" & $RS.Fields(9).value, $ListView1)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
        
        
        
EndFunc   ;==>dumdb

本帖子中包含更多资源

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

×
发表于 2011-8-10 07:52:57 | 显示全部楼层

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
$mdb = @ScriptDir & "\db1.mdb"
$Table = "db1"
$T = "*"

$Form1_1 = GUICreate("Form1", 880, 442, 183, 114)
$ListView1 = GUICtrlCreateListView("编号 |品名|类型|数量|单价|总价|经办人|单位或个人|货款|日期", 56, 24, 673, 297)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 60)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 50)
$Label1 = GUICtrlCreateLabel("合计:元", 64, 344, 120, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

dumdb()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func dumdb()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $Table)
        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 & "|" & $RS.Fields(6).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(8).value & "|" & $RS.Fields(9).value, $ListView1)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
        Local $iTotal = 0
        For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
                $iTotal += _GUICtrlListView_GetItemText($ListView1, $i, 4)
        Next
        GUICtrlSetData($Label1, '合计:' & $iTotal & ' 元')
EndFunc   ;==>dumdb

发表于 2011-8-10 08:17:10 | 显示全部楼层
谢谢分享。。。下次学习会用到,,留个记号
发表于 2011-8-10 08:28:17 | 显示全部楼层
代码收下,谢谢...
发表于 2011-8-10 08:30:57 | 显示全部楼层
好象代码出错吧?
 楼主| 发表于 2011-8-10 11:18:17 | 显示全部楼层
回复 6# ceoguang


      Local $iTotal = 0


        For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1


                $iTotal += _GUICtrlListView_GetItemText($ListView1, $i, 4)


        Next

能不能注解一下呀。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-27 11:58 , Processed in 0.083729 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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