在VB.NET 2008中向WPF ListView添加多列数据
我一直在搜索,但我一直无法找到一种将多列数据添加到 WPF VB.NET ListView 中的半途而废的方法。我添加的数据不是来自数据源。
我想在搜索文件时将文件和日期添加到 ListView 中。
以下是 ListView 的 XAML 以及添加到其中的 GridView:
<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>
以下是我尝试添加到 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
请帮助我在 WPF VB.NET 2008 中填充此 ListView。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会觉得很傻,但代码隐藏中的第二列称为
theDate
,但 XAML 中的第二列绑定到theDay
。欢迎来到运行时数据绑定的危险。将来查看调试版本的输出窗口以查找绑定错误。编辑:
这实际上是一个变相的不同问题:Visual Basic 中匿名类型的语法是什么?
例如:
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 totheDay
. 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?
For example: