This is the xaml of listview
<ListView Grid.Column="1" Height="auto" Name="ListView1" Width="auto" AllowDrop ="True" >
<ListView.View>
<GridView >
<GridViewColumn Header="File Name" />
<GridViewColumn Header="Path" />
<GridViewColumn Header="type" />
</GridView>
</ListView.View>
</ListView>
I add a item into the listbox, but it add a row with three same value
ListView1.Items.Add("abcd")
I have also tried 开发者_如何学Csome ways, but still have problem
So I would like to know how I can add different value to second column
Dim x As ItemCollection
x.Add("a")
x.Add("b")
x.Add("c")
ListView1.Items.Add(x)
Dim x As New ItemCollection
x.Add("a")
x.Add("b")
x.Add("c")
ListView1.Items.Add(x)
And How to get the value at second column?
I have tried this code, but it just return the second character of first column, I can't find any ways to access the second column
ListView1.Items(0)(1)
I think you need to bind the list for this to work.
I made this sample class:
Public Class ListViewItemTemplate
Public Property FileName As String
Public Property FilePath As String
Public Property FileType As String
End Class
Changed the xaml to include DisplayMember bindings:
<ListView Name="ListView1" Width="auto" AllowDrop ="True" Margin="0,0,0,41">
<ListView.View>
<GridView >
<GridViewColumn Header="File Name" DisplayMemberBinding="{Binding Path=FileName}" />
<GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path=FilePath}"/>
<GridViewColumn Header="type" DisplayMemberBinding="{Binding Path=FileType}" />
</GridView>
</ListView.View>
</ListView>
And loaded some sample data:
Dim itemsList As New List(Of ListViewItemTemplate)
Dim item As New ListViewItemTemplate
item.FileName = "FileName A"
item.FilePath = "FilePath A"
item.FileType = "FileType A"
itemsList.Add(item)
item = New ListViewItemTemplate
item.FileName = "FileName B"
item.FilePath = "FilePath B"
item.FileType = "FileType B"
itemsList.Add(item)
item = New ListViewItemTemplate
item.FileName = "FileName C"
item.FilePath = "FilePath C"
item.FileType = "FileType C"
itemsList.Add(item)
ListView1.ItemsSource = itemsList
Good luck!!
精彩评论