标题:listview virtual mode 的问题,求解!!
只看楼主
laomms
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-4-16
 问题点数:0 回复次数:1 
listview virtual mode 的问题,求解!!
程序代码:
,想将数据库中的各项导入到listview,由于数据庞大,所以用 virtual mode,但是始终不成功!!

Public Class customer
    Public cnn As New OleDb.OleDbConnection
    Public cmd As New OleDb.OleDbCommand
    Public da As New OleDb.OleDbDataAdapter
    Public dr As OleDb.OleDbDataReader
    Dim ds As New DataSet
    Dim dt As New DataTable
    Dim listitem() As ListViewItem
    Private firstItem As Integer
    Dim arr As ArrayList
    Private Sub customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.Items.Clear()
        ListView1.GridLines = True
        ListView1.VirtualMode = True
        ListView1.VirtualListSize = 0

        Call CheckImportListView()

    End Sub
    Private Sub CheckImportListView()
        Dim sql As String
        cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & Application.StartupPath & "\database.mde "
        sql = "Select ID,name,TEL from [客户]"
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, cnn)
        da.Fill(ds, "客户")
        Dim i As Integer = 0
        listitem = New ListViewItem(ds.Tables("客户").Rows.Count - 1) {}
        For Each dRow As DataRow In ds.Tables("客户").Rows
            For i = 1 To ds.Tables("客户").Columns.Count
                listitem(i) = New ListViewItem(dRow("ID").ToString)
                //listitem(i) = New ListViewItem(dRow("name").ToString)
                i = i + 1
            Next
        Next
        ListView1.VirtualListSize = ds.Tables("客户").Rows.Count
    End Sub

    Private Sub ListView1_RetrieveVirtualItem(ByVal sender As Object, ByVal e As System.Windows.Forms.RetrieveVirtualItemEventArgs) Handles ListView1.RetrieveVirtualItem
        Dim x As Integer = e.ItemIndex * e.ItemIndex
        e.Item = New ListViewItem(x.ToString())
    End Sub
End Class

virtualListview中只显示第一列(ID)的数据,如何添加显示第二列(name)、第三列(Tel)数据.
搜索更多相关主题的帖子: 数据库 customer 
2014-09-02 13:39
laomms
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-4-16
得分:0 
回复 楼主 laomms
程序代码:
        da.Fill(ds, "客户")
        Dim i As Integer = 0
        Dim n As Integer = 0
        listitem = New ListViewItem(ds.Tables("客户").Rows.Count - 1) {}
        For Each dRow As DataRow In ds.Tables("客户").Rows
            listitem(i) = New ListViewItem(dRow(0).ToString)
            For n = ds.Tables("客户").Columns.Count To 1 Step -1
                listitem(i).SubItems.Add(dRow(ds.Tables("客户").Columns.Count - n).ToString)
            Next
            i = i + 1
        Next


解决!
2014-09-02 15:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-435595-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.244860 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved