🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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
#102350
Author: "ChrissP."
Date: Thu, 23 Jun 2011 09:56
29 lines
703 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
#102351
Author: Maciej Tokarz
Date: Mon, 27 Jun 2011 20:53
153 lines
4397 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
#102352
Author: "ChrissP."
Date: Tue, 26 Jul 2011 14:37
14 lines
370 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