在VB.NET 2008中向WPF ListView添加多列数据

发布于 2024-11-04 10:58:22 字数 1330 浏览 0 评论 0原文

我一直在搜索,但我一直无法找到一种将多列数据添加到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2024-11-11 10:58:22

您会觉得很傻,但代码隐藏中的第二列称为 theDate,但 XAML 中的第二列绑定到 theDay。欢迎来到运行时数据绑定的危险。将来查看调试版本的输出窗口以查找绑定错误。

编辑:

这实际上是一个变相的不同问题:Visual Basic 中匿名类型的语法是什么?

例如:

Dim product = New With {Key .Name = "paperclips", .Price = 1.29}

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?

For example:

Dim product = New With {Key .Name = "paperclips", .Price = 1.29}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文