Zdravim musim delat neco spatne... Mam jeden hlavni formular, ze ktereho volam druhy na kterem je prvek ListView - naplnuji ho v tom hlavnim formulari. Nevim proc, ale kdyz kliknu poprve na tlacitko, ktere ma nacist data do ListView v druhem formulari napoprve se neobjevi nic, kdyz tlacitko stisknu podruhe, objevi se vsechny polozky 2x !!! Nize posilam kod, ktery je stazeny z napovedy a jen sem ho rozdelil do dvou formularu. Proto abyste to mohli vyzkouset vam staci 2 formulare - Main, na kterem je tlacitko, ktere vyvola druhy formular Form1 na kterem je ListView - lw1 Main
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")
With Form1.lw1
' Create columns for the items and subitems.
.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
.Columns.Add("Column 4", -2, HorizontalAlignment.Center)
'Add the items to the ListView.
.Items.AddRange(New ListViewItem() {item1, item2, item3})
.Refresh()
End With
Form1.ShowDialog()
End Sub
a druhy formular, na kterem je prvek ListView - lw1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a new ListView control.
With lw1
' Set the view to show details.
.View = View.Details
' Allow the user to edit item text.
.LabelEdit = False
' Allow the user to rearrange columns.
.AllowColumnReorder = False
' Display check boxes.
.CheckBoxes = False
' Select the item and subitems when selection is made.
.FullRowSelect = True
' Display grid lines.
.GridLines = False
.Refresh()
End With
End Sub 'CreateMyListView
nechapu, proc se to na poprve neobjevi a pak hned dvakrat :-(
|