Home All Groups Group Topic Archive Search About

Treeview population directly from MSAccess

Author
5 Mar 2006 10:15 PM
Paul
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

Author
6 Mar 2006 1:20 AM
Ken Tucker [MVP]
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/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp

http://www.vb-tips.com/default.aspx?ID=4f216359-e2a6-46de-beef-04dfd3b31b2b

http://support.microsoft.com/default.aspx?scid=kb;en-us;308063

Ken
-------------------
Show quoteHide quote
"Paul" <t***@tester.com> wrote in message
news:%23bVN4IKQGHA.3984@TK2MSFTNGP14.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
>
Author
6 Mar 2006 11:30 AM
Paul
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,DetailId 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?ID=4f216359-e2a6-46de-beef-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





Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ORxg2wLQGHA.2816@TK2MSFTNGP15.phx.gbl...
> 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/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp
>
> http://www.vb-tips.com/default.aspx?ID=4f216359-e2a6-46de-beef-04dfd3b31b2b
>
> http://support.microsoft.com/default.aspx?scid=kb;en-us;308063
>
> Ken
> -------------------
> "Paul" <t***@tester.com> wrote in message
> news:%23bVN4IKQGHA.3984@TK2MSFTNGP14.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
>>
>
>
Author
7 Mar 2006 11:53 PM
Ken Tucker [MVP]
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.OleDb


Public Class Form1

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

        strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
        strConn &= "Data Source = c:\Northwind.mdb;"


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

        conn.Open()
        dr = cmd.ExecuteReader
        Do While dr.Read
            Dim nd As New TreeNode(dr.Item("ProductName").ToString)
            nd.Nodes.Add(String.Format("Price {0}",
Convert.ToDecimal(dr.Item("UnitPrice")).ToString("c")))
            nd.Nodes.Add(String.Format("Units In Stock {0}",
dr.Item("UnitsInStock").ToString))
            nd.Nodes.Add(String.Format("Units On Order {0}",
dr.Item("UnitsOnOrder").ToString))
            TreeView1.Nodes.Add(nd)
        Loop
        conn.Close()
    End Sub
End Class


Ken
-----------------
Show quoteHide quote
"Paul" <t***@tester.com> wrote in message
news:O9GEOFRQGHA.5560@TK2MSFTNGP10.phx.gbl...
> 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,DetailId 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?ID=4f216359-e2a6-46de-beef-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]" <vb***@bellsouth.net> wrote in message
> news:ORxg2wLQGHA.2816@TK2MSFTNGP15.phx.gbl...
>> 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/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp
>>
>> http://www.vb-tips.com/default.aspx?ID=4f216359-e2a6-46de-beef-04dfd3b31b2b
>>
>> http://support.microsoft.com/default.aspx?scid=kb;en-us;308063
>>
>> Ken
>> -------------------
>> "Paul" <t***@tester.com> wrote in message
>> news:%23bVN4IKQGHA.3984@TK2MSFTNGP14.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
>>>
>>
>>
>
>
Author
8 Mar 2006 11:25 AM
Paul
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


Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%23YY0nJkQGHA.4688@TK2MSFTNGP10.phx.gbl...
> 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.OleDb
>
>
> Public Class Form1
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim conn As OleDbConnection
>        Dim strConn As String
>        Dim cmd As OleDbCommand
>        Dim dr As OleDbDataReader
>
>        strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
>        strConn &= "Data Source = c:\Northwind.mdb;"
>
>
>        conn = New OleDbConnection(strConn)
>        cmd = New OleDbCommand("Select * from Products", conn)
>
>        conn.Open()
>        dr = cmd.ExecuteReader
>        Do While dr.Read
>            Dim nd As New TreeNode(dr.Item("ProductName").ToString)
>            nd.Nodes.Add(String.Format("Price {0}",
> Convert.ToDecimal(dr.Item("UnitPrice")).ToString("c")))
>            nd.Nodes.Add(String.Format("Units In Stock {0}",
> dr.Item("UnitsInStock").ToString))
>            nd.Nodes.Add(String.Format("Units On Order {0}",
> dr.Item("UnitsOnOrder").ToString))
>            TreeView1.Nodes.Add(nd)
>        Loop
>        conn.Close()
>    End Sub
> End Class
>
>
> Ken
> -----------------
> "Paul" <t***@tester.com> wrote in message
> news:O9GEOFRQGHA.5560@TK2MSFTNGP10.phx.gbl...
>> 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,DetailId 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?ID=4f216359-e2a6-46de-beef-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]" <vb***@bellsouth.net> wrote in message
>> news:ORxg2wLQGHA.2816@TK2MSFTNGP15.phx.gbl...
>>> 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/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp
>>>
>>> http://www.vb-tips.com/default.aspx?ID=4f216359-e2a6-46de-beef-04dfd3b31b2b
>>>
>>> http://support.microsoft.com/default.aspx?scid=kb;en-us;308063
>>>
>>> Ken
>>> -------------------
>>> "Paul" <t***@tester.com> wrote in message
>>> news:%23bVN4IKQGHA.3984@TK2MSFTNGP14.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
>>>>
>>>
>>>
>>
>>
>
>
Author
6 Mar 2006 6:31 AM
Cor Ligthert [MVP]
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