LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

VB的Listview保存读取

admin
2013年12月14日 22:6 本文热度 5614

完整代码


注:Listview定义了4个列,自己需要几列改下就好


Option Explicit
'读写INI文件
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long


Private Sub Form_Load()
Randomize
End Sub


Private Sub 随机值_Click()
Dim i As Integer, j As Integer, lv As ListItem
ListView1.ListItems.Clear
For i = 0 To 14
Set lv = ListView1.ListItems.Add(, , i + 1)
For j = 0 To 2
lv.ListSubItems.Add , , CInt(Rnd * 30)
Next j
Next i
End Sub


Private Sub 保存_Click()
Dim si As Integer, sj As Integer, tmpstr As String
If ListView1.ListItems.Count = 0 Then MsgBox "没有可保存的内容", vbInformation, "提示": Exit Sub
tmpstr = ListView1.ListItems.Count
WritePrivateProfileString "统计项", "总行数", tmpstr, App.Path & "\ABC.ini"
tmpstr = ListView1.ListItems(1).ListSubItems.Count
WritePrivateProfileString "统计项", "总列数", tmpstr, App.Path & "\ABC.ini"
With ListView1.ListItems
For si = 1 To .Count
WritePrivateProfileString "第" & si & "行", "第1列", .Item(si).Text, App.Path & "\ABC.ini"
For sj = 1 To .Item(si).ListSubItems.Count
WritePrivateProfileString "第" & si & "行", "第" & sj + 1 & "列", .Item(si).SubItems(sj), App.Path & "\ABC.ini"
Next sj
Next si
End With
MsgBox "保存成功!", vbInformation, "提示"
End Sub


Private Sub 读取_Click()
Dim sr As Integer, sc As Integer, li As Integer, lj As Integer, tmptxt As String, lvs As ListItem
tmptxt = Space$(100)
GetPrivateProfileString "统计项", "总行数", "0", tmptxt, 100, App.Path & "\ABC.ini"
sr = CInt(tmptxt) '总行数
tmptxt = Space$(100)
GetPrivateProfileString "统计项", "总行数", "0", tmptxt, 100, App.Path & "\ABC.ini"
sc = CInt(tmptxt)
If sr = 0 Then
MsgBox "总行数为零哦"
Exit Sub
Else
ListView1.ListItems.Clear
End If
For li = 1 To sr
For lj = 1 To sc '这里你的列表
tmptxt = Space$(100)
GetPrivateProfileString "第" & li & "行", "第" & lj & "列", "", tmptxt, 100, App.Path & "\ABC.ini"
If lj = 1 Then
Set lvs = ListView1.ListItems.Add(, , tmptxt)
Else
lvs.ListSubItems.Add , , tmptxt
End If
Next lj
Next li
End Sub


该文章在 2013/12/14 22:06:18 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved