Treeview population directly from MSAccess

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    Treeview population directly from MSAccess

    Hi,
    I am a self taught VBA programmer, and I'm trying to learn VB2005 Express
    (The price was right).
    I like the look of the treeview control, and I'd like to use it as a menu
    system for my users, the options they are allowed to see are all different
    and specified in a MSACCESS table.

    Can I populate a Treeview directly from my MSAccess table ?

    I can then of course filter the table to only show that users options.

    As I am new to this I could do with some babysitting.

    Thanks for any help

    Paul


  • Ken Tucker [MVP]

    #2
    Re: Treeview population directly from MSAccess

    Hi,

    You can not bind a treeview to a datasource. Here are some links on
    how to fill a treeview from a database.







    Ken
    -------------------
    "Paul" <test@tester.co m> wrote in message
    news:%23bVN4IKQ GHA.3984@TK2MSF TNGP14.phx.gbl. ..[color=blue]
    > Hi,
    > I am a self taught VBA programmer, and I'm trying to learn VB2005 Express
    > (The price was right).
    > I like the look of the treeview control, and I'd like to use it as a menu
    > system for my users, the options they are allowed to see are all different
    > and specified in a MSACCESS table.
    >
    > Can I populate a Treeview directly from my MSAccess table ?
    >
    > I can then of course filter the table to only show that users options.
    >
    > As I am new to this I could do with some babysitting.
    >
    > Thanks for any help
    >
    > Paul
    >[/color]


    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Treeview population directly from MSAccess

      Paul,

      You can build an Treeview for a AccessTable, however as a lot of people are
      you probably trying to build something as your own Accesssystem with this.
      Be aware that you alone can never get that functionality (and your users
      expect that) as that MS access with that big Microsoft organisation has.

      Just my thought,

      Cor


      Comment

      • Paul

        #4
        Re: Treeview population directly from MSAccess

        Hi Ken,
        Thanks for your response.
        I checked out the code on your website and it worked great, but I need to
        make my application fill the treeview from my access table.

        I created and populated table with the 3 columns (ParentID,Detai lId and
        Description) , and created a datasource to it, then I added a datagrid to my
        form from the database, so a binding source etc where all automatically
        created.

        Can you show me how I would now amend the code from

        to fill the treeview from my table rather than from the (if I understand it
        correctly) "Virtual" table that your code creates ?


        If it helps, I called my table TBL_MENU.

        Thanks again for your help

        Paul





        "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
        news:ORxg2wLQGH A.2816@TK2MSFTN GP15.phx.gbl...[color=blue]
        > Hi,
        >
        > You can not bind a treeview to a datasource. Here are some links on
        > how to fill a treeview from a database.
        >
        > http://msdn.microsoft.com/library/de...cntrlsamp3.asp
        >
        > http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b
        >
        > http://support.microsoft.com/default...b;en-us;308063
        >
        > Ken
        > -------------------
        > "Paul" <test@tester.co m> wrote in message
        > news:%23bVN4IKQ GHA.3984@TK2MSF TNGP14.phx.gbl. ..[color=green]
        >> Hi,
        >> I am a self taught VBA programmer, and I'm trying to learn VB2005 Express
        >> (The price was right).
        >> I like the look of the treeview control, and I'd like to use it as a menu
        >> system for my users, the options they are allowed to see are all
        >> different and specified in a MSACCESS table.
        >>
        >> Can I populate a Treeview directly from my MSAccess table ?
        >>
        >> I can then of course filter the table to only show that users options.
        >>
        >> As I am new to this I could do with some babysitting.
        >>
        >> Thanks for any help
        >>
        >> Paul
        >>[/color]
        >
        >[/color]


        Comment

        • Ken Tucker [MVP]

          #5
          Re: Treeview population directly from MSAccess

          Hi,

          One possible solution. I used a datareader to load the treeview. I
          loaded the unitprice and converted it to a decimal to format the price. You
          could have used dr.getdecimal to get the price but you need to specify the
          column number instead of name.

          Imports System.Data.Ole Db


          Public Class Form1

          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          Dim conn As OleDbConnection
          Dim strConn As String
          Dim cmd As OleDbCommand
          Dim dr As OleDbDataReader

          strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"
          strConn &= "Data Source = c:\Northwind.md b;"


          conn = New OleDbConnection (strConn)
          cmd = New OleDbCommand("S elect * from Products", conn)

          conn.Open()
          dr = cmd.ExecuteRead er
          Do While dr.Read
          Dim nd As New TreeNode(dr.Ite m("ProductName" ).ToString)
          nd.Nodes.Add(St ring.Format("Pr ice {0}",
          Convert.ToDecim al(dr.Item("Uni tPrice")).ToStr ing("c")))
          nd.Nodes.Add(St ring.Format("Un its In Stock {0}",
          dr.Item("UnitsI nStock").ToStri ng))
          nd.Nodes.Add(St ring.Format("Un its On Order {0}",
          dr.Item("UnitsO nOrder").ToStri ng))
          TreeView1.Nodes .Add(nd)
          Loop
          conn.Close()
          End Sub
          End Class


          Ken
          -----------------
          "Paul" <test@tester.co m> wrote in message
          news:O9GEOFRQGH A.5560@TK2MSFTN GP10.phx.gbl...[color=blue]
          > Hi Ken,
          > Thanks for your response.
          > I checked out the code on your website and it worked great, but I need to
          > make my application fill the treeview from my access table.
          >
          > I created and populated table with the 3 columns (ParentID,Detai lId and
          > Description) , and created a datasource to it, then I added a datagrid to
          > my form from the database, so a binding source etc where all automatically
          > created.
          >
          > Can you show me how I would now amend the code from
          > http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b
          > to fill the treeview from my table rather than from the (if I understand
          > it correctly) "Virtual" table that your code creates ?
          >
          >
          > If it helps, I called my table TBL_MENU.
          >
          > Thanks again for your help
          >
          > Paul
          >
          >
          >
          >
          >
          > "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
          > news:ORxg2wLQGH A.2816@TK2MSFTN GP15.phx.gbl...[color=green]
          >> Hi,
          >>
          >> You can not bind a treeview to a datasource. Here are some links
          >> on how to fill a treeview from a database.
          >>
          >> http://msdn.microsoft.com/library/de...cntrlsamp3.asp
          >>
          >> http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b
          >>
          >> http://support.microsoft.com/default...b;en-us;308063
          >>
          >> Ken
          >> -------------------
          >> "Paul" <test@tester.co m> wrote in message
          >> news:%23bVN4IKQ GHA.3984@TK2MSF TNGP14.phx.gbl. ..[color=darkred]
          >>> Hi,
          >>> I am a self taught VBA programmer, and I'm trying to learn VB2005
          >>> Express (The price was right).
          >>> I like the look of the treeview control, and I'd like to use it as a
          >>> menu system for my users, the options they are allowed to see are all
          >>> different and specified in a MSACCESS table.
          >>>
          >>> Can I populate a Treeview directly from my MSAccess table ?
          >>>
          >>> I can then of course filter the table to only show that users options.
          >>>
          >>> As I am new to this I could do with some babysitting.
          >>>
          >>> Thanks for any help
          >>>
          >>> Paul
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Paul

            #6
            Re: Treeview population directly from MSAccess

            Ken,
            You are my new best friend.

            This works and its fantastic, Just as I was about to give in on VB and stick
            with MsAccess VBA you showed me the way.

            Of course this means I'll be progressing my project and asking lots more
            questions !

            Thanks again

            Paul


            "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
            news:%23YY0nJkQ GHA.4688@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > Hi,
            >
            > One possible solution. I used a datareader to load the treeview. I
            > loaded the unitprice and converted it to a decimal to format the price.
            > You could have used dr.getdecimal to get the price but you need to specify
            > the column number instead of name.
            >
            > Imports System.Data.Ole Db
            >
            >
            > Public Class Form1
            >
            > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
            > System.EventArg s) Handles MyBase.Load
            > Dim conn As OleDbConnection
            > Dim strConn As String
            > Dim cmd As OleDbCommand
            > Dim dr As OleDbDataReader
            >
            > strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"
            > strConn &= "Data Source = c:\Northwind.md b;"
            >
            >
            > conn = New OleDbConnection (strConn)
            > cmd = New OleDbCommand("S elect * from Products", conn)
            >
            > conn.Open()
            > dr = cmd.ExecuteRead er
            > Do While dr.Read
            > Dim nd As New TreeNode(dr.Ite m("ProductName" ).ToString)
            > nd.Nodes.Add(St ring.Format("Pr ice {0}",
            > Convert.ToDecim al(dr.Item("Uni tPrice")).ToStr ing("c")))
            > nd.Nodes.Add(St ring.Format("Un its In Stock {0}",
            > dr.Item("UnitsI nStock").ToStri ng))
            > nd.Nodes.Add(St ring.Format("Un its On Order {0}",
            > dr.Item("UnitsO nOrder").ToStri ng))
            > TreeView1.Nodes .Add(nd)
            > Loop
            > conn.Close()
            > End Sub
            > End Class
            >
            >
            > Ken
            > -----------------
            > "Paul" <test@tester.co m> wrote in message
            > news:O9GEOFRQGH A.5560@TK2MSFTN GP10.phx.gbl...[color=green]
            >> Hi Ken,
            >> Thanks for your response.
            >> I checked out the code on your website and it worked great, but I need to
            >> make my application fill the treeview from my access table.
            >>
            >> I created and populated table with the 3 columns (ParentID,Detai lId and
            >> Description) , and created a datasource to it, then I added a datagrid to
            >> my form from the database, so a binding source etc where all
            >> automatically created.
            >>
            >> Can you show me how I would now amend the code from
            >> http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b
            >> to fill the treeview from my table rather than from the (if I understand
            >> it correctly) "Virtual" table that your code creates ?
            >>
            >>
            >> If it helps, I called my table TBL_MENU.
            >>
            >> Thanks again for your help
            >>
            >> Paul
            >>
            >>
            >>
            >>
            >>
            >> "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
            >> news:ORxg2wLQGH A.2816@TK2MSFTN GP15.phx.gbl...[color=darkred]
            >>> Hi,
            >>>
            >>> You can not bind a treeview to a datasource. Here are some links
            >>> on how to fill a treeview from a database.
            >>>
            >>> http://msdn.microsoft.com/library/de...cntrlsamp3.asp
            >>>
            >>> http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b
            >>>
            >>> http://support.microsoft.com/default...b;en-us;308063
            >>>
            >>> Ken
            >>> -------------------
            >>> "Paul" <test@tester.co m> wrote in message
            >>> news:%23bVN4IKQ GHA.3984@TK2MSF TNGP14.phx.gbl. ..
            >>>> Hi,
            >>>> I am a self taught VBA programmer, and I'm trying to learn VB2005
            >>>> Express (The price was right).
            >>>> I like the look of the treeview control, and I'd like to use it as a
            >>>> menu system for my users, the options they are allowed to see are all
            >>>> different and specified in a MSACCESS table.
            >>>>
            >>>> Can I populate a Treeview directly from my MSAccess table ?
            >>>>
            >>>> I can then of course filter the table to only show that users options.
            >>>>
            >>>> As I am new to this I could do with some babysitting.
            >>>>
            >>>> Thanks for any help
            >>>>
            >>>> Paul
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            Working...