Article View: pl.comp.lang.vbasic
Article #104824Re: VB.Net mysql i TreeView
From: Maciej Tokarz
Date: Mon, 27 Jun 2011 18:53
Date: Mon, 27 Jun 2011 18:53
152 lines
5367 bytes
5367 bytes
W dniu 2011-06-23 11:56, ChrissP. pisze:
> CategoryID | ParentID | CategoryName | Level
>
> Ostatnie pole (level) oznacza poziom w hierarchii, jaki zajmuje dana
> kategoria.
>
Witaj,
U siebie stosuję trochę odmienne podejście. To znaczy zamiast level mam
informację: SortOrder - czyli kolejność wczytywania nodów, ich
sortowania przy wypełnianiu kolekcji:
Dim data = _
(From x In dbContext.Komorki _
Order By x.SortOrder _
Select New Komorka With { _
.IdKomorki = x.IdKomorki, _
.IdRodzica = x.IdRodzica, _
.NazwaKomorki = x.NazwaKomorki}).ToList
Nie robiłem testów przeciążając drzewko, zdaje się że około 30k może
"pociągnąć".
Poniższy przykład nie będzie może odpowiedzią na Twoje pytanie,
przedstawiam sposób w jaki ładuję dane:
Public Module NodeKomorkiHelper
<System.Runtime.CompilerServices.Extension()> _
Public Function GetKomorkiTreeNodes _
(ByVal komorki As IEnumerable(Of SisServiceKomorka)) _
As IEnumerable(Of NodeKomorka)
Return GetChildren(komorki, Nothing)
End Function
Private Function GetChildren _
(ByVal komorki As IEnumerable(Of SisServiceKomorka), _
ByVal parent As SisServiceKomorka) _
As IEnumerable(Of NodeKomorka)
Dim children = From k In komorki _
Where (parent IsNot Nothing _
AndAlso k.IdRodzica = parent.IdKomorki) _
OrElse (parent Is Nothing AndAlso k.IdRodzica = 0) _
Select New NodeKomorka() With _
{ _
.Komorka = k, _
.Childs = GetChildren(komorki, k) _
}
Return children.ToList()
End Function
End Module
Imports Sis.SisServiceReference
Imports System.ComponentModel
Public Class NodeKomorka
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New
PropertyChangedEventArgs(propertyName))
End Sub
Private m_Komorka As SisServiceKomorka
Public Property Komorka() As SisServiceKomorka
Get
Return m_Komorka
End Get
Set(ByVal value As SisServiceKomorka)
m_Komorka = value
End Set
End Property
Private m_IsExpanded As Boolean
Public Property IsExpanded() As Boolean
Get
Return m_IsExpanded
End Get
Set(ByVal value As Boolean)
If m_IsExpanded <> value Then
m_IsExpanded = value
NotifyPropertyChanged("IsExpanded")
End If
End Set
End Property
Private m_IsSelected As Boolean
Public Property IsSelected() As Boolean
Get
Return m_IsSelected
End Get
Set(ByVal value As Boolean)
If m_IsSelected <> value Then
m_IsSelected = value
NotifyPropertyChanged("IsSelected")
End If
End Set
End Property
Private m_Childs As IEnumerable(Of NodeKomorka)
Public Property Childs() As IEnumerable(Of NodeKomorka)
Get
Return m_Childs
End Get
Set(ByVal value As IEnumerable(Of NodeKomorka))
m_Childs = value
End Set
End Property
End Class
Imports System.Windows.Data
Public Class MyTreeView
Inherits TreeView
Protected Overrides Function GetContainerForItemOverride() As
DependencyObject
Return New MyTreeViewItem()
End Function
End Class
Public Class MyTreeViewItem
Inherits TreeViewItem
Public Sub New()
SetBinding(IsExpandedProperty, New Binding("IsExpanded") With
{.Mode = BindingMode.TwoWay})
SetBinding(IsSelectedProperty, New Binding("IsSelected") With
{.Mode = BindingMode.TwoWay})
End Sub
Protected Overrides Function GetContainerForItemOverride() As
DependencyObject
Return New MyTreeViewItem()
End Function
End Class
Pozdrawiam,
--
Maciej Tokarz
http://my-poi.pl
Technical Details
Message-ID:
<iuajju$8uu$1@news.onet.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!.POSTED!not-for-mailReferences:
<itv2kd$eh3$1@news.onet.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!.POSTED!not-for-mail From: Maciej Tokarz <mactok@my-poi.pl> Newsgroups: pl.comp.lang.vbasic Subject: Re: VB.Net mysql i TreeView Date: Mon, 27 Jun 2011 20:53:46 +0200 Organization: http://onet.pl Lines: 152 Message-ID: <iuajju$8uu$1@news.onet.pl> References: <itv2kd$eh3$1@news.onet.pl> NNTP-Posting-Host: static-78-9-150-225.ssp.dialog.net.pl Mime-Version: 1.0 X-Trace: news.onet.pl 1309200830 9182 78.9.150.225 (27 Jun 2011 18:53:50 GMT) X-Complaints-To: niusy@onet.pl NNTP-Posting-Date: Mon, 27 Jun 2011 18:53:50 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; pl; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: <itv2kd$eh3$1@news.onet.pl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit