Thread View: pl.comp.lang.vbasic
3 messages
3 total messages
Started by ChrissP.
Thu, 23 Jun 2011 09:56
VB.Net mysql i TreeView
Author: ChrissP.
Date: Thu, 23 Jun 2011 09:56
Date: Thu, 23 Jun 2011 09:56
28 lines
1618 bytes
1618 bytes
Witam Mam tabelę w bazie (MySQL, ale to mało istotne), której struktura przedstawia się nastęoująco: CategoryID | ParentID | CategoryName | Level Ostatnie pole (level) oznacza poziom w hierarchii, jaki zajmuje dana kategoria. I teraz muszę z pomocą tych kategorii stworzyć kontrolkę TreeView, niestety rekordów jest ponad 20 tyś, dlatego nie jest rozwiązaniem ładowanie rekordów rekurencyjnie (za długo trwa). Poszczególne pozycje muszą zachować CategoryID i CategoryName Znacie jakiś szybki sposób na zbudowanie kontrolki? Z góry dzięki za odpowiedzi... -- Pozdrawiam Krzysztof Najczestsze klamstwo w internecie? "Szukalem, nie znalazlem..."
Re: VB.Net mysql i TreeView
Author: 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
Re: VB.Net mysql i TreeView
Author: ChrissP.
Date: Tue, 26 Jul 2011 14:37
Date: Tue, 26 Jul 2011 14:37
13 lines
1339 bytes
1339 bytes
[cut] Dzięki i przepraszam, że dopiero odpisuję :) W końcu inaczej sprawę rozwiązałem. Po prostu ładuję najwyższy poziom i doładowuję następny dla danego nod'a jeśli jest potrzebny, osobnym zapytaniem. Przez vbmysql direct idzie błyskawicznie... -- Pozdrawiam Krzysztof Najczestsze klamstwo w internecie? "Szukalem, nie znalazlem..."
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads