大米CMS官网论坛,大米站长联盟,大米站长之家,大米开发者社区

 找回密码
 注册大米会员

QQ登录

只需一步,快速开始

查看: 2776|回复: 0
打印 上一主题 下一主题

VB.NET wpf使用listview

[复制链接]

498

主题

775

帖子

7647

积分

超级版主

Rank: 8Rank: 8

积分
7647

授权用户

跳转到指定楼层
楼主
发表于 2021-10-14 14:09:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
(1)布局文件
  1. <ListView x:Name="ListView1" HorizontalAlignment="Left" Height="360" Margin="0,82,0,0" VerticalAlignment="Top" Width="772" Grid.ColumnSpan="4" BorderThickness="0">
  2.             <ListView.View>
  3.                 <GridView>
  4.                     <GridViewColumn Header="文件夹名" Width="200" DisplayMemberBinding="{Binding Path=fold_name}"/>
  5.                     <GridViewColumn Header="文件夹路径" Width="300" DisplayMemberBinding="{Binding Path=fold_path}"/>
  6.                     <GridViewColumn Header="图标" Width="130" DisplayMemberBinding="{Binding Path=fold_icon}"/>
  7.                     <GridViewColumn Header="加密时间" Width="170" DisplayMemberBinding="{Binding Path=do_time}"/>
  8.                 </GridView>
  9.             </ListView.View>
  10.         </ListView>
复制代码

(2)绑定数据库resource
  1. ListView1.Width = Me.Width
  2.         Dim da As OleDbDataAdapter = New OleDbDataAdapter("select * from fold order by id desc", conn)
  3.         Dim ds As New DataSet
  4.         da.Fill(ds, "fold")
  5.         ListView1.Items.Clear()
  6.         If ds.Tables.Count > 0 Then
  7.             For i = 0 To ds.Tables(0).Rows.Count - 1
  8.                 Dim dr = ds.Tables(0).Rows(i)
  9.                 ListView1.Items.Add(New DataItem(dr.ItemArray(1).ToString, dr.ItemArray(2).ToString, dr.ItemArray(3).ToString, dr.ItemArray(4).ToString))
  10.             Next
  11.         End If
复制代码

(3)collection item类定义
  1. Public Class DataItem
  2.     Private _fold_name As String
  3.     Public Property fold_name() As String
  4.         Get
  5.             Return _fold_name
  6.         End Get
  7.         Set(value As String)
  8.             _fold_name = value
  9.         End Set
  10.     End Property

  11.     Private _fold_path As String
  12.     Public Property fold_path() As String
  13.         Get
  14.             Return _fold_path
  15.         End Get
  16.         Set(value As String)
  17.             _fold_path = value
  18.         End Set
  19.     End Property

  20.     Private _fold_icon As String
  21.     Public Property fold_icon() As String
  22.         Get
  23.             Return _fold_icon
  24.         End Get
  25.         Set(value As String)
  26.             _fold_icon = value
  27.         End Set
  28.     End Property

  29.     Private _do_time As String
  30.     Public Property do_time() As String
  31.         Get
  32.             Return _do_time
  33.         End Get
  34.         Set(value As String)
  35.             _do_time = value
  36.         End Set
  37.     End Property


  38.     Public Sub New(ByVal fpath As String, ByVal fname As String, ByVal ficon As String, ByVal dotime As String)
  39.         Me.fold_icon = ficon
  40.         Me.fold_name = fname
  41.         Me.fold_path = fpath
  42.         Me.do_time = dotime
  43.     End Sub
  44. End Class
复制代码

效果图


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册大米会员

本版积分规则

QQ|小黑屋|大米CMS社区 ( 蜀ICP备11002200号-2广告联系:广告联系 

Powered by 大米CMS

© 2010-2020 大米CMS Inc.

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