VB.NET ListView控件經(jīng)驗(yàn)總結(jié)
本文向大家介紹VB.NET ListView控件,可能好多人還不了解VB.NET ListView控件,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。
VB.NET ListView控件在程序開發(fā)過程中的使用是非常廣泛的。因?yàn)槠洳恢С謹(jǐn)?shù)據(jù)庫的綁定,所以在數(shù)據(jù)庫程序開發(fā)領(lǐng)域無法與datagridview抗衡,但是ListView的確是一個(gè)非常好用的控件。下面就把一個(gè)簡單的VB.NET ListView控件的例子發(fā)出來。
- Public Class heroClass hero
- Private s_name As String
- Private s_age As Long
- Private s_like As String
- Public Property myName()Property myName() As String
- Get
- Return s_name
- End Get
- Set(ByVal value As String)
- s_name = value
- End Set
- End Property
- Public Property myAge()Property myAge() As Long
- Get
- Return s_age
- End Get
- Set(ByVal value As Long)
- s_age = value
- End Set
- End Property
- Public Property myLike()Property myLike() As String
- Get
- Return s_like
- End Get
- Set(ByVal value As String)
- s_like = value
- End Set
- End Property
- End Class
VB.NET ListView控件裝載數(shù)據(jù)
- Private Sub btnLoad_Click()Sub btnLoad_Click(ByVal sender As
- System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
- s_flag = True
- Me.lv1.CheckBoxes = True
- Dim i As Integer
- Const maxCount As Long = 10
- Dim iItem As ListViewItem
- Dim aHero As hero
- For i = maxNumber To maxNumber + maxCount - 1
- Dim rd As New System.Random(Environment.TickCount * i)
- aHero = New her
- iItem = New ListViewItem
- aHero.myName = firstName & i.ToString
- aHero.myAge = System.Math.Round(rd.NextDouble * 100, 0)
- aHero.myLike = createLike(i)
- iItem.Text = aHero.myName
- iItem.Tag = aHero
- iItem.SubItems.Add(aHero.myAge)
- iItem.SubItems.Add(aHero.myLike)
- Me.lv1.Items.Add(iItem)
- heroList.Add(aHero.myName, aHero)
- Next
- maxNumber = i
- If Me.lv1.Items.Count > 0 Then
- Me.lv1.Items.Item(0).Checked = True
- End If
- s_flag = False
- End Sub
【編輯推薦】