Databinding on the treeview control

Hi Experts,

I'm currently writing a VB.Net 2005 application on the Dot Net Framework 2.0.  I have a Dataview with about 800 records that I use to poulate a treeview with.  Each record in the dataview represents a node in the treeview.  A record can either be a parent node or a child node of another node.

Currently I populate the treeview by adding the nodes one at a time.  After adding a node, I filter the dataview to get all the child nodes of the node just added.  I then add them one by one and for each of them filter the dataview again to get the next set of child nodes.

Someone told me that it is possilble in .Net 2 to bind such a dataview to a treeview control if you have all fields that indicate which records are children of which records...  Is it possible?  How could I do this?

If required, I could post the structure of the table....

Thanks
PantoffelSlippersAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:

' This is the C# implementation of Data Binding TreeView Control converted and modified 
' from VB .NET by LZF of www.codeproject.com. The original code and article, 
' writen by Duncan Mackenzie of MSDN, can be found at 
' "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp" 
' 
' Following lines are the copyright from the original code 
 
' 
' * Copyright (C) 2002 Microsoft Corporation 
' * All rights reserved. 
' * 
' * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
' * EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
' * MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
' * 
' * Date: May 2002 
' * Author: Duncan Mackenzie 
' * 
' * Requires the release version of .NET Framework 
' 
 
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
 
Namespace ControlLib
  Public Class dbTreeViewCtrl
    Inherits System.Windows.Forms.TreeView
 
    Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
      ' TODO: Add custom paint code here 
 
      ' Calling the base class OnPaint 
      MyBase.OnPaint(pe)
    End Sub
 
    Private m_autoBuild As Boolean = True
 
    Public Property AutoBuildTree() As Boolean
      Get
        Return Me.m_autoBuild
      End Get
      Set(ByVal value As Boolean)
        Me.m_autoBuild = value
      End Set
    End Property
 
#Region "Data Binding"
    Private m_currencyManager As CurrencyManager = Nothing
    Private m_ValueMember As String
    Private m_DisplayMember As String
    Private m_oDataSource As Object
 
    <Category("Data")> _
    Public Property DataSource() As Object
      Get
        Return m_oDataSource
      End Get
      Set(ByVal value As Object)
        If value Is Nothing Then
          Me.m_currencyManager = Nothing
          Me.Nodes.Clear()
        Else
          If Not (TypeOf value Is IList OrElse TypeOf m_oDataSource Is IListSource) Then
            Throw (New System.Exception("Invalid DataSource"))
          Else
            If TypeOf value Is IListSource Then
              Dim myListSource As IListSource = DirectCast(value, IListSource)
              If myListSource.ContainsListCollection = True Then
                Throw (New System.Exception("Invalid DataSource"))
              End If
            End If
            Me.m_oDataSource = value
            Me.m_currencyManager = DirectCast(Me.BindingContext(value), CurrencyManager)
            If Me.AutoBuildTree Then
              BuildTree()
            End If
          End If
        End If
      End Set
    End Property
    ' end of DataSource property 
    <Category("Data")> _
    Public Property ValueMember() As String
      Get
        Return Me.m_ValueMember
      End Get
      Set(ByVal value As String)
        Me.m_ValueMember = value
      End Set
    End Property
 
    <Category("Data")> _
    Public Property DisplayMember() As String
      Get
        Return Me.m_DisplayMember
      End Get
      Set(ByVal value As String)
        Me.m_DisplayMember = value
      End Set
    End Property
 
    Public Function GetValue(ByVal index As Integer) As Object
      Dim innerList As IList = Me.m_currencyManager.List
      If innerList IsNot Nothing Then
        If (Me.ValueMember <> "") AndAlso (index >= 0 AndAlso 0 < innerList.Count) Then
          Dim pdValueMember As PropertyDescriptor
          pdValueMember = Me.m_currencyManager.GetItemProperties()(Me.ValueMember)
          Return pdValueMember.GetValue(innerList(index))
        End If
      End If
      Return Nothing
    End Function
 
    Public Function GetDisplay(ByVal index As Integer) As Object
      Dim innerList As IList = Me.m_currencyManager.List
      If innerList IsNot Nothing Then
        If (Me.DisplayMember <> "") AndAlso (index >= 0 AndAlso 0 < innerList.Count) Then
          Dim pdDisplayMember As PropertyDescriptor
          pdDisplayMember = Me.m_currencyManager.GetItemProperties()(Me.ValueMember)
          Return pdDisplayMember.GetValue(innerList(index))
        End If
      End If
      Return Nothing
    End Function
 
#End Region
 
#Region "Building the Tree"
 
    Private treeGroups As New ArrayList()
 
    Public Sub BuildTree()
      Me.Nodes.Clear()
      If (Me.m_currencyManager IsNot Nothing) AndAlso (Me.m_currencyManager.List IsNot Nothing) Then
        Dim innerList As IList = Me.m_currencyManager.List
        Dim currNode As TreeNodeCollection = Me.Nodes
        Dim currGroupIndex As Integer = 0
        Dim currListIndex As Integer = 0
 
 
        If Me.treeGroups.Count > currGroupIndex Then
          Dim currGroup As Group = DirectCast(treeGroups(currGroupIndex), Group)
          Dim myFirstNode As dbTreeNode = Nothing
          Dim pdGroupBy As PropertyDescriptor
          Dim pdValue As PropertyDescriptor
          Dim pdDisplay As PropertyDescriptor
 
          pdGroupBy = Me.m_currencyManager.GetItemProperties()(currGroup.GroupBy)
          pdValue = Me.m_currencyManager.GetItemProperties()(currGroup.ValueMember)
          pdDisplay = Me.m_currencyManager.GetItemProperties()(currGroup.DisplayMember)
 
          Dim currGroupBy As String = Nothing
          If innerList.Count > currListIndex Then
            Dim currObject As Object
            While currListIndex < innerList.Count
              currObject = innerList(currListIndex)
              If pdGroupBy.GetValue(currObject).ToString() <> currGroupBy Then
                currGroupBy = pdGroupBy.GetValue(currObject).ToString()
 
                myFirstNode = New dbTreeNode(currGroup.Name, pdDisplay.GetValue(currObject).ToString(), currObject, pdValue.GetValue(innerList(currListIndex)), currGroup.ImageIndex, currGroup.SelectedImageIndex, _
                currListIndex)
 
                currNode.Add(DirectCast(myFirstNode, TreeNode))
              Else
                AddNodes(currGroupIndex, currListIndex, myFirstNode.Nodes, currGroup.GroupBy)
              End If
              ' end while 
            End While
            ' end if 
          End If
        Else
          ' end if 
          While currListIndex < innerList.Count
            AddNodes(currGroupIndex, currListIndex, Me.Nodes, "")
          End While
        End If
        ' end else 
        If Me.Nodes.Count > 0 Then
          Me.SelectedNode = Me.Nodes(0)
 
        End If
      End If
      ' end if 
    End Sub
 
    Private Sub AddNodes(ByVal currGroupIndex As Integer, ByRef currentListIndex As Integer, ByVal currNodes As TreeNodeCollection, ByVal prevGroupByField As String)
      Dim innerList As IList = Me.m_currencyManager.List
      Dim pdPrevGroupBy As System.ComponentModel.PropertyDescriptor = Nothing
      Dim prevGroupByValue As String = Nothing
 
 
      Dim currGroup As Group
 
      If prevGroupByField <> "" Then
        pdPrevGroupBy = Me.m_currencyManager.GetItemProperties()(prevGroupByField)
      End If
 
      currGroupIndex += 1
 
      If treeGroups.Count > currGroupIndex Then
        currGroup = DirectCast(treeGroups(currGroupIndex), Group)
        Dim pdGroupBy As PropertyDescriptor = Nothing
        Dim pdValue As PropertyDescriptor = Nothing
        Dim pdDisplay As PropertyDescriptor = Nothing
 
        pdGroupBy = Me.m_currencyManager.GetItemProperties()(currGroup.GroupBy)
        pdValue = Me.m_currencyManager.GetItemProperties()(currGroup.ValueMember)
        pdDisplay = Me.m_currencyManager.GetItemProperties()(currGroup.DisplayMember)
 
        Dim currGroupBy As String = Nothing
 
        If innerList.Count > currentListIndex Then
          If pdPrevGroupBy IsNot Nothing Then
            prevGroupByValue = pdPrevGroupBy.GetValue(innerList(currentListIndex)).ToString()
          End If
 
          Dim myFirstNode As dbTreeNode = Nothing
          Dim currObject As Object = Nothing
 
          While (currentListIndex < innerList.Count) AndAlso (pdPrevGroupBy IsNot Nothing) AndAlso (pdPrevGroupBy.GetValue(innerList(currentListIndex)).ToString() = prevGroupByValue)
            currObject = innerList(currentListIndex)
            If pdGroupBy.GetValue(currObject).ToString() <> currGroupBy Then
              currGroupBy = pdGroupBy.GetValue(currObject).ToString()
 
              myFirstNode = New dbTreeNode(currGroup.Name, pdDisplay.GetValue(currObject).ToString(), currObject, pdValue.GetValue(innerList(currentListIndex)), currGroup.ImageIndex, currGroup.SelectedImageIndex, _
              currentListIndex)
 
              currNodes.Add(DirectCast(myFirstNode, TreeNode))
            Else
              AddNodes(currGroupIndex, currentListIndex, myFirstNode.Nodes, currGroup.GroupBy)
            End If
          End While
        End If
      Else
        Dim myNewLeafNode As dbTreeNode
        Dim currObject As Object = Me.m_currencyManager.List(currentListIndex)
 
        If (Me.DisplayMember IsNot Nothing) AndAlso (Me.ValueMember IsNot Nothing) AndAlso (Me.DisplayMember <> "") AndAlso (Me.ValueMember <> "") Then
          Dim pdDisplayloc As PropertyDescriptor = Me.m_currencyManager.GetItemProperties()(Me.DisplayMember)
          Dim pdValueloc As PropertyDescriptor = Me.m_currencyManager.GetItemProperties()(Me.ValueMember)
 
          myNewLeafNode = New dbTreeNode(IIf(Me.Tag Is Nothing, "", Me.Tag.ToString()), pdDisplayloc.GetValue(currObject).ToString(), currObject, pdValueloc.GetValue(currObject), currentListIndex)
        Else
          myNewLeafNode = New dbTreeNode("", currentListIndex.ToString(), currObject, currObject, Me.ImageIndex, Me.SelectedImageIndex, _
          currentListIndex)
        End If
 
        currNodes.Add(DirectCast(myNewLeafNode, TreeNode))
        currentListIndex += 1
      End If
    End Sub
#End Region
 
#Region "Groups"
 
    Public Sub RemoveGroup(ByVal group As Group)
      If treeGroups.Contains(group) Then
        treeGroups.Remove(group)
        If Me.AutoBuildTree Then
          BuildTree()
        End If
      End If
    End Sub
 
    Public Sub RemoveGroup(ByVal groupName As String)
      For Each group As Group In Me.treeGroups
        If group.Name = groupName Then
          RemoveGroup(group)
          Return
        End If
      Next
    End Sub
 
    Public Sub RemoveAllGroups()
      Me.treeGroups.Clear()
      If Me.AutoBuildTree Then
        Me.BuildTree()
      End If
    End Sub
 
    Public Sub AddGroup(ByVal group As Group)
      Try
        treeGroups.Add(group)
        If Me.AutoBuildTree Then
          Me.BuildTree()
        End If
      Catch e As NotSupportedException
        MessageBox.Show(e.Message)
      Catch e As System.Exception
        Throw e
      End Try
    End Sub
 
    Public Sub AddGroup(ByVal name As String, ByVal groupBy As String, ByVal displayMember As String, ByVal valueMember As String, ByVal imageIndex As Integer, ByVal selectedImageIndex As Integer)
      Dim myNewGroup As New Group(name, groupBy, displayMember, valueMember, imageIndex, selectedImageIndex)
      Me.AddGroup(myNewGroup)
    End Sub
 
    Public Function GetGroups() As Group()
      Return DirectCast(treeGroups.ToArray(Type.[GetType]("Group")), Group())
    End Function
 
#End Region
 
    Public Sub SetLeafData(ByVal name As String, ByVal displayMember As String, ByVal valueMember As String, ByVal imageIndex As Integer, ByVal selectedImageIndex As Integer)
      Me.Tag = name
      Me.DisplayMember = displayMember
      Me.ValueMember = valueMember
      Me.ImageIndex = imageIndex
      Me.SelectedImageIndex = selectedImageIndex
    End Sub
 
    Public Function IsLeafNode(ByVal node As TreeNode) As Boolean
      Return (node.Nodes.Count = 0)
    End Function
 
#Region "Keeping Everything In Sync"
 
    Public Function FindNodeByValue(ByVal value As Object) As TreeNode
      Return FindNodeByValue(value, Me.Nodes)
    End Function
 
    Public Function FindNodeByValue(ByVal Value As Object, ByVal nodesToSearch As TreeNodeCollection) As TreeNode
      Dim i As Integer = 0
      Dim currNode As TreeNode
      Dim leafNode As dbTreeNode
 
      While i < nodesToSearch.Count
        currNode = nodesToSearch(i)
        i += 1
        If currNode.LastNode Is Nothing Then
          leafNode = DirectCast(currNode, dbTreeNode)
          If leafNode.Value.ToString() = Value.ToString() Then
            Return currNode
          End If
        Else
          currNode = FindNodeByValue(Value, currNode.Nodes)
          If currNode IsNot Nothing Then
            Return currNode
          End If
        End If
      End While
 
      Return Nothing
    End Function
 
    Private Function FindNodeByPosition(ByVal posIndex As Integer) As TreeNode
      Return FindNodeByPosition(posIndex, Me.Nodes)
    End Function
 
    Private Function FindNodeByPosition(ByVal posIndex As Integer, ByVal nodesToSearch As TreeNodeCollection) As TreeNode
      Dim i As Integer = 0
      Dim currNode As TreeNode
      Dim leafNode As dbTreeNode
 
      While i < nodesToSearch.Count
        currNode = nodesToSearch(i)
        i += 1
        If currNode.Nodes.Count = 0 Then
          leafNode = DirectCast(currNode, dbTreeNode)
          If leafNode.Position = posIndex Then
            Return currNode
          Else
            currNode = FindNodeByPosition(posIndex, currNode.Nodes)
            If currNode IsNot Nothing Then
              Return currNode
            End If
          End If
        End If
      End While
      Return Nothing
    End Function
 
    Protected Overloads Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
      Dim leafNode As dbTreeNode = DirectCast(e.Node, dbTreeNode)
 
      If leafNode IsNot Nothing Then
        If Me.m_currencyManager.Position <> leafNode.Position Then
          Me.m_currencyManager.Position = leafNode.Position
        End If
      End If
      ' TODO: Add MyTreeViewCtrl.OnAfterSelect implementation 
      MyBase.OnAfterSelect(e)
    End Sub
 
#End Region
 
  End Class
 
  Public Class Group
    Private groupName As String
    Private groupByMember As String
    Private groupByDisplayMember As String
    Private groupByValueMember As String
 
    Private groupImageIndex As Integer
    Private groupSelectedImageIndex As Integer
 
    Public Sub New(ByVal name As String, ByVal groupBy As String, ByVal displayMember As String, ByVal valueMember As String, ByVal imageIndex As Integer, ByVal selectedImageIndex As Integer)
      Me.ImageIndex = imageIndex
      Me.Name = name
      Me.GroupBy = groupBy
      Me.DisplayMember = displayMember
      Me.ValueMember = valueMember
      Me.SelectedImageIndex = selectedImageIndex
    End Sub
 
    Public Sub New(ByVal name As String, ByVal groupBy As String, ByVal displayMember As String, ByVal valueMember As String, ByVal imageIndex As Integer)
      Me.New(name, groupBy, displayMember, valueMember, imageIndex, imageIndex)
    End Sub
 
    Public Sub New(ByVal name As String, ByVal groupBy As String)
      Me.New(name, groupBy, groupBy, groupBy, -1, -1)
    End Sub
 
    Public Property SelectedImageIndex() As Integer
      Get
        Return groupSelectedImageIndex
      End Get
      Set(ByVal value As Integer)
        groupSelectedImageIndex = value
      End Set
    End Property
    Public Property ImageIndex() As Integer
      Get
        Return groupImageIndex
      End Get
      Set(ByVal value As Integer)
        groupImageIndex = value
      End Set
    End Property
 
    Public Property Name() As String
      Get
        Return groupName
      End Get
      Set(ByVal value As String)
        groupName = value
      End Set
    End Property
 
    Public Property GroupBy() As String
      Get
        Return groupByMember
      End Get
      Set(ByVal value As String)
        groupByMember = value
      End Set
    End Property
 
    Public Property DisplayMember() As String
      Get
        Return groupByDisplayMember
      End Get
      Set(ByVal value As String)
        groupByDisplayMember = value
      End Set
    End Property
 
    Public Property ValueMember() As String
      Get
        Return groupByValueMember
      End Get
      Set(ByVal value As String)
        groupByValueMember = value
      End Set
    End Property
  End Class
 
  Public Class dbTreeNode
    Inherits TreeNode
    Private m_groupName As String
    Private m_value As Object
    Private m_item As Object
    Private m_position As Integer
 
    Public Sub New()
    End Sub
 
    Public Sub New(ByVal groupName As String, ByVal text As String, ByVal item As Object, ByVal value As Object, ByVal imageIndex As Integer, ByVal selectedImgIndex As Integer, _
    ByVal position As Integer)
      Me.GroupName = groupName
      Me.Text = text
      Me.Item = item
      Me.Value = value
      Me.ImageIndex = imageIndex
      Me.SelectedImageIndex = selectedImgIndex
      Me.m_position = position
    End Sub
 
    Public Sub New(ByVal groupName As String, ByVal text As String, ByVal item As Object, ByVal value As Object, ByVal position As Integer)
      Me.GroupName = groupName
      Me.Text = text
      Me.Item = item
      Me.Value = value
      Me.m_position = position
    End Sub
 
    Public Property GroupName() As String
      Get
        Return m_groupName
      End Get
      Set(ByVal value As String)
        Me.m_groupName = value
      End Set
    End Property
 
    Public Property Item() As Object
      Get
        Return m_item
      End Get
      Set(ByVal value As Object)
        m_item = value
      End Set
    End Property
 
    Public Property Value() As Object
      Get
        Return m_value
      End Get
      Set(ByVal value As Object)
        m_value = value
      End Set
    End Property
 
    Public ReadOnly Property Position() As Integer
      Get
        Return m_position
      End Get
    End Property
  End Class
 
End Namespace

Open in new window

0
 
Bob LearnedCommented:
You can bind the TreeView to anything that inherits from HierarchicalDataSourceControl.  Currently in 2.0 that is the SiteMapDataSource and the XmlDataSource.

Bob
0
 
PantoffelSlippersAuthor Commented:
Thanks Bob!

I'm not really familiar with the HierarchicalDataSourceControl, SiteMapDataSource or XmlDataSource.

Would you mind please elaborating on your previous comment?  Alternatively I could just try investigate these topics....

Thanks
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Bob LearnedCommented:
1) What is the datasource for the TreeView?

2) What kind of information are you showing in the TreeView?

3) Is this going to be used for information display or site navigation?

Bob
0
 
PantoffelSlippersAuthor Commented:
Bob,

>>>>>>>>1) What is the datasource for the TreeView?
It will be a Datatable or Dataview.  The structure of which will look like this:
StructID - auto increment number used as primary key
StructCode - Varchar.  Code to represent position in hierarchy.  Example: 01 & 01-01 & 01-02.
StructDesc - Varchar.  Name of the record.  This will become the text of the treeview node.
StructLinkID - Varchar.  Contains the StructCode of the parentnode for this record.

>>>>>>>2) What kind of information are you showing in the TreeView?
Not sure what you mean...   But the hierarchy will represent a folder structure (taxonomy) of a Microsoft SharePoint site.  My client has a standard folder structure for its sharepoint sites which is stored in a SQL Server table as detailed in question 1.  My application edits the master copy of this structure.  Before editing may begin, the whole structure must be displayed in a tree view.  The user will typically right-click on a node and have a context menu that will allow for an option to add a sub-folder.  Hope this helps???


>>>>>>>>3) Is this going to be used for information display or site navigation?
This is a desktop app so I imagine the answer could only be "display information only".


Does this help?  If you require any other information please let me know.
Thanks
0
 
Bob LearnedCommented:
>>This is a desktop app
Disregard what I said, since that applies to ASP.NET, which why you wouldn't have heard of SiteMapDataSource or XmlDataSource.

With WinForms, it is significantly different.  

Proof-of-concept article:

Data Binding TreeView in C#
http://www.codeproject.com/KB/tree/dbTree.aspx

Bob
0
 
PantoffelSlippersAuthor Commented:
Sorry Bob!!!

Should have mentioned it's a desktop app.

Please accept my apologies.

I'm having a look at the article right now.
Thanks
0
 
Bob LearnedCommented:
No problem, I always think ASP.NET before WinForms, and I didn't ask!!

Bob
0
 
PantoffelSlippersAuthor Commented:
Bob,

I've got the same habit, only with WinForms ....

I've run into a problem.  

From the article I got:

    this.myDataView.Sort = pub_id, au_id, title_id;
    this.myTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0);
    this.myTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);

The problem is that my treeview control does not have an "AddGroup" member.  The article is based on dot net 1.0.  I'm using 2.0.  I looked for a similar member but couldn't find anything.

You have any suggestions?

Thanks
 
0
 
Bob LearnedConnect With a Mentor Commented:
Here is updated source code for 2.0:
' This is the C# implementation of Data Binding PictureBox converted from 
' VB .NET by LZF of www.codeproject.com. The original code and article, 
' writen by Duncan Mackenzie of MSDN, can be found at 
' "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp" 
' 
' Following block is the copyright and the description from the original code 
 
'Copyright (C) 2002 Microsoft Corporation 
'All rights reserved. 
 
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
'EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
'MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
 
'Date: May 2002 
'Author: Duncan Mackenzie 
 
'Requires the release version of .NET Framework 
 
'This control allows you to provide a file path 
'to its ImagePath property and have it load the image 
 
'Having this ImagePath property allows the control 
'to be databound, therefore supporting the display 
'of a picture based on a path stored in a database. 
 
'thinking that missing files and bad images would be 
'common, I am handling those errors simply by 
'clearing the image. That way you won't get an exception 
'but you also won't see the last record's image 
'with the current record's data. 
 
'If you would rather have an exception occur, 
'simply rewrite the ImagePath property and the 
'UpdateImage functions to remove the Exists check 
'and the Try Catch... like this; 
 
'Public Property ImagePath() As String 
' Get 
' Return m_ImagePath 
' End Get 
' Set(ByVal Value As String) 
' If Value <> m_ImagePath Then 
' m_ImagePath = Value 
' UpdateImage() 
' RaiseEvent ImagePathChanged(CObj(Me), New EventArgs()) 
' End If 
' End Set 
'End Property 
 
'Private Sub UpdateImage() 
' Me.Image = New Bitmap(ImagePath) 
'End Sub 
 
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
 
Namespace ControlLib
 
  Public Class dbImageBox
    Inherits System.Windows.Forms.PictureBox
    Private m_ImagePath As String
 
    Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
      ' TODO: Add custom paint code here 
 
      ' Calling the base class OnPaint 
      MyBase.OnPaint(pe)
    End Sub
 
    Public Property ImagePath() As String
      Get
        Return Me.m_ImagePath
      End Get
      Set(ByVal value As String)
        If value <> Me.m_ImagePath Then
          Me.m_ImagePath = value
          If System.IO.File.Exists(value) Then
            UpdateImage()
          Else
            Me.Image = Nothing
          End If
        End If
      End Set
    End Property
 
    Public Sub UpdateImage()
      Try
        Me.Image = Image.FromFile(ImagePath)
      Catch e As System.Exception
        MessageBox.Show(e.Message)
        Me.Image = Nothing
      End Try
    End Sub
 
  End Class
End Namespace

Open in new window

0
 
Bob LearnedCommented:
dbTreeViewCtrl has the AddGroup method.

Bob
0
 
PantoffelSlippersAuthor Commented:
Thanks Bob

I'm trying again
0
 
PantoffelSlippersAuthor Commented:
Thank you
0
 
salemanokcCommented:
learned one.  I am not nearly as advanced as you and also a VB.NET fella.  Trying to understand the implementation of the control.  Particularly the binding.  I have a simple table using a KEY field and a ParentID field.  The PARENTID field is NULL if it is a root record or contains the KEY value of it's parent record.  I also have a text field called PRODUCT that I want to disply in the tree.

I have played with the control for hours and can't make it work.  I keep getting a "can't bind to property error" from the control.  Do I use a binding object?  What is the field to bind?  I think it is a two line piece of code.  1) to setup the binding object and 2) to set to the control.

Thanks in advance for your help!  I am sure it is obvious and I will hit my head when I see it. :-)

0
All Courses

From novice to tech pro — start learning today.