Im using VB.net and WPF .
In a WPF page ,i have created a listview to show records added.
In XAML,i have
But in vbcode i need to bind datas to its items
i have tried like
--------------------------------------------------------
i = ListViewDonotCall.Items.Count
ListViewDonotCall.Items.Add(TextBoxName.Text.ToString())
---> ListViewDonotCall.Items(i).SubItems.Add(TextBoxMobileNo.Text.ToString())
i = i + 1
---------------------------------------------------------
But in the arrow line ,it gives error,sub item error
How can i bind data to multiple columns
Thanks in advance
Naveen
Raaj KumarPosted Mar 5, 2010, 8:39 AM
See there is no Property called subitems inside Items. So what you can do is like create a class and add 2 of these properties(Name and MobileNumber). Create a collection List or ObservableCollection and add few items to it. Finally assign the collection to the Itemssource property of the ListView.
In XAML bind this Name and MobileNumber Property to the DisplayMemberBinding like this,
and in Codebehind do like this,
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
AddHandler Loaded, AddressOf Window1_Loaded
End Sub
Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
PopulateList()
End Sub
Protected Sub PopulateList()
Dim personData As New ObservableCollection(Of Person)()
personData.Add(New Person())
personData.Add(New Person())
personData.Add(New Person())
personData.Add(New Person())
ListViewDonotCall.ItemsSource = personData
End Sub
End Class
Public Class Person
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _MobileNumber As Integer
Public Property MobileNumber() As Integer
Get
Return _MobileNumber
End Get
Set(ByVal value As Integer)
_MobileNumber = value
End Set
End Property
End Class
Since I am not very good in VB.NET, hope you got what I meant to say. I just used an online C# to VB.NET converter for this.
Regards,
raaj