I finally am going to make a concerted effort to learn VB.Net. So I installed VB.Net 2005 Express on my machine and away I go. I think the best way for me to learn how to program in VB.Net is to do it in small bits. I decided to start with the Listview. I want to learn how to use a listview and to do it properly meaning using it the way it is suppose to be used. Please take a look at my code and let me know how I can improve it.
VB Code:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'FrontDataSet.Copy_of_Features' table. You can move, or remove it, as needed. Dim a As Integer With ListView1 .View = View.Details End With Call lvwInitialize(ListView1) Call DoTheChart() Call ResizeForm() End Sub Private Sub lvwInitialize(ByVal lvw As ListView) Dim lvh As ColumnHeader Dim a As Integer With lvw .Clear() .FullRowSelect = True With .Columns For a = 1 To 3 lvh = .Add("Column " & a) lvh.Width = lvw.Width / 3 Next a End With End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Call LoadData(ListView1) End Sub Private Sub LoadData(ByVal lvw As ListView) Dim lvi As ListViewItem Dim i As Integer Dim a As Integer With lvw .FullRowSelect = True .View = View.Details .Items.Clear() For i = 0 To 10 lvi = New ListViewItem() lvi.Text = String.Format("Col1-Row{0}", i) For a = 1 To .Columns.Count lvi.SubItems.Add("") '<=== Why do I need this line? lvi.SubItems(a).Text = String.Format("Col" & a & "-Row{0}", i) Next a .Items.Add(lvi) Next i End With End Sub Private Sub ResizeForm() Dim lvw As ListView Dim lvh As ColumnHeader Dim a As Integer lvw = ListView1 If Me.WindowState = FormWindowState.Minimized Then Exit Sub With lvw .Top = 0 .Left = 0 .Width = ClientSize.Width - 10 .Height = (ClientSize.Height) - 30 With .Columns For a = 0 To .Count - 1 lvh = .Item(a) lvh.Width = lvw.Width / 3 Next a End With End With With Button1 .Top = ClientSize.Height - .Height - 5 End With End Sub Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize Call ResizeForm() End Sub End Class
Thanks!![]()




Reply With Quote