Hi
I have nested observablecollection. It contains n levels.
How to get maximum id (integer type) from this nested observablecollection, as i have to add new item at the selected node.
In order to add new item into nested observablecollection, i require the id of last item in collection.
Following is the Observablecollection:
Imports System.Collections.ObjectModel Imports Telerik.Windows.Controls Imports System.ComponentModel Public Class BefundItem Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged(ByVal info As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info)) End Sub Public Sub New(Id As String, ParentId As String, text As String) Me.Id = Id Me.ParentId = ParentId Me.Text = text Me.Items = New ObservableCollection(Of BefundItem)() End Sub Private _Id As Integer Public Property Id() As Integer Get Return _Id End Get Set(ByVal value As Integer) _Id = value NotifyPropertyChanged("Id") End Set End Property Private _ParentId As Integer Public Property ParentId() As Integer Get Return _ParentId End Get Set(ByVal value As Integer) _ParentId = value NotifyPropertyChanged("ParentId") End Set End Property Private _Text As String Public Property Text() As String Get Return _Text End Get Set(ByVal value As String) _Text = value NotifyPropertyChanged("Text") End Set End Property Public ReadOnly Property IsExpandable() As Boolean Get Return True End Get End Property Public m_Items As ObservableCollection(Of BefundItem) Public Property Items() As ObservableCollection(Of BefundItem) Get Return m_Items End Get Set(value As ObservableCollection(Of BefundItem)) m_Items = value Me.NotifyPropertyChanged("Items") End Set End Property Public Property Count() As Integer Get Return m_Count End Get Set(value As Integer) m_Count = value Me.NotifyPropertyChanged("Count") End Set End Property Private m_Count As Integer End Class
Code to fetch data from observablecollection to Treelistview:
Private Sub Fill_Befunde_Treeview() Try For j As Integer = 1 To 2 id = j Parentid = 0 text = j Dim parent As New BefundItem(id, Parentid, text) For i As Integer = 1 To 4 id = i Parentid = j text = j & "." & i Dim child As New BefundItem(id, Parentid, text) parent.Items.Add(child) Next data.Add(parent) Next trvlstBefunde_Befunde.ItemsSource = data Catch ex As Exception MsgBox(ex.Message) End Try End Sub
Thank you in advance.
S.Naik