2011-06-21

ListView

1. Design ListView like this picture.



2. Set Listview property

FullRowSelect = True
GridLines = True
UseCompatibleStateImageBehavior = False
View = Details

3. Using System.Windows.Forms.ListView

4. Sample code to add item to listview (When click button add item to listview)
Dim pObj As New ListViewItem("Code")
pObj.SubItems.Add("Item Name")
pObj.SubItems.Add("10.00")
pObj.SubItems.Add("1")
pObj.SubItems.Add("1.50"))
pObj.SubItems.Add("15.00")
pObj.Tag = 1 ' keep materail id ListView1.Items.Add(pObj)

5. Sample code to delete item in listview when press delete on keyboard.
Private Sub ListView1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstMaterial.KeyUp
If e.KeyCode = Keys.Delete AndAlso ListView1.SelectedItems.Count > 0 Then
For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
ListView1.Items.RemoveAt(ListView1.SelectedItems(i).Index)
Next
End If
End Sub

7 comments:

  1. thanks for the interesting information

    ReplyDelete
  2. Thanks for sharing ! Very useful.

    ReplyDelete
  3. Photograph examinating released many of you and additionally it’s reasonably great thing. I will undoubtedly save your items your blog site.

    ReplyDelete
  4. This is a helpful guide for understanding how to use ListViews in Windows Forms.

    ReplyDelete

Thanks for your comment.