在WPF列表视图中绑定多功能列 [英] Binding mutilple columns in WPF listview
问题描述
大家好,
我正在使用VB.NET和WPF.
我需要在WPF列表视图中绑定多个列.
在XAML中,我创建了一个listview控件,并在其中创建了两个列标题.
在VB代码中,我已将数据绑定到创建的列:
Hi all,
I am using VB.NET and WPF.
I need to bind multiple columns in WPF listview.
In XAML, I have created a listview control and created two column headers in it.
In VB code, I have binded data to created columns:
listview.items.add
listview.subitems.add
但无法将数据绑定到Listview的多个列
请对此问题提供帮助
提前谢谢.
Naveen ....:confused:
but not able to bind datas to multiple columns of Listview
Kindly help on this issue
Thanks in advance.
Naveen.... :confused:
推荐答案
WPF的ListView
不像Windows窗体ListView
那样具有子项". br/>
用您的C#代码执行此操作:
WPF''sListView
doesn''t have "SubItems" like the Windows FormsListView
does.
do this in yur C# code:
listView.ItemsSource = myCollection;
以及XAML中的类似内容
and something like this in your XAML
<ListView Margin="6,180,5,5"
Name="listView"
ItemsSource="{Binding}" >
<ListView.View>
<GridView>
<GridViewColumn Width="400" Header="Title"
DisplayMemberBinding="{Binding Path=MyProperty}" />
</GridView>
</ListView.View>
</ListView>
再次感谢约翰·西蒙斯先生
在这里,IAM使用vb.net编码和WPF应用程序
这就是我在Windows中尝试过的方式
Thanks again Mr.John Simmons
Here iam using vb.net Coding and WPF application
This is how i tried in Windows
con.Open()
Dim strSQL As String = "Select * from Addressbook"
Dim cmd As New SqlClient.SqlCommand(strSQL, con)
Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader()
Dim j As Integer = 0
If reader.HasRows Then
While reader.Read()
ListViewAddressBook.Items.Add("")
ListViewAddressBook.Items(j).SubItems.Add(reader(2))
ListViewAddressBook.Items(j).SubItems.Add(reader(3))
ListViewAddressBook.Items(j).SubItems.Add(reader(4))
ListViewAddressBook.Items(j).SubItems.Add(reader(5))
AddressBookMobileArrayList.Add(ListViewAddressBook.Items(j).SubItems(3).Text)
j = j + 1
End While
End If
reader.Close()
con.Close()
但是当我在WPF中尝试此操作时,它给出了错误
请指导我约翰·西蒙斯先生
在此先感谢
Naveen ...
BUT WHEN I TRIED THIS IN WPF,its giving error
Kindly guide me Mr.John Simmons
Thanks in advance
Naveen...
这篇关于在WPF列表视图中绑定多功能列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!