Add multi-column data to WPF ListView in VB.NET 2008
I've been searching and searching, but I haven't been able to find a halfway-decent way of adding multiple columns of data into a WPF VB.NET ListView. The data I'm adding is not from a datasource.
I would like to add files and dates to the ListView while I'm searching for the files.
Here is the XAML for the ListView and the GridView added to it:
<Grid>
<ListView Margin="0,101,0,0"
Name="dataListView">
<ListView.View>
<GridView x:Name="myGridView">
<GridViewColumn Width="225"
开发者_如何学运维 Header="File Name"
DisplayMemberBinding="{Binding theName}"/>
<GridViewColumn Width="165"
Header="Date/Time"
DisplayMemberBinding="{Binding theDay}"/>
</GridView>
</ListView.View>
</ListView>
Here is the code-behind where I'm trying to add to the ListView:
Private Sub searchPath_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles searchPath.Click
Dim dirInfo As New DirectoryInfo(sourcePath.Text)
Dim theName, theDate As String
dataListView.Items.Clear()
For Each filInfo In dirInfo.GetFiles("*.QBB", SearchOption.AllDirectories)
dataListView.Items.Add(new {theName = filInfo.Name, theDate = filInfo.LastWriteTime})
Next
End Sub
Please help me populate this ListView in WPF VB.NET 2008.
Thanks!
You're going to feel silly but the second column in your code-behind is called theDate
but the second column in your XAML is bound to theDay
. Welcome to the perils of run-time databinding. In the future have a look at the output window of the debug build for binding errors.
Edit:
This was actual a different question in disguise: What is the syntax for anonymous types in Visual Basic?
- Anonymous Types
For example:
Dim product = New With {Key .Name = "paperclips", .Price = 1.29}
精彩评论