By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,119 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

Treeview population directly from MSAccess

P: n/a
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
Mar 5 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" <te**@tester.com> wrote in message
news:%2****************@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

Mar 6 '06 #2

P: n/a
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
Mar 6 '06 #3

P: n/a
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?...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]" <vb***@bellsouth.net> wrote in message
news:OR**************@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/de...cntrlsamp3.asp

http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b

http://support.microsoft.com/default...b;en-us;308063

Ken
-------------------
"Paul" <te**@tester.com> wrote in message
news:%2****************@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


Mar 6 '06 #4

P: n/a
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" <te**@tester.com> wrote in message
news:O9**************@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?...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]" <vb***@bellsouth.net> wrote in message
news:OR**************@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/de...cntrlsamp3.asp

http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b

http://support.microsoft.com/default...b;en-us;308063

Ken
-------------------
"Paul" <te**@tester.com> wrote in message
news:%2****************@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



Mar 8 '06 #5

P: n/a
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]" <vb***@bellsouth.net> wrote in message
news:%2****************@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" <te**@tester.com> wrote in message
news:O9**************@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?...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]" <vb***@bellsouth.net> wrote in message
news:OR**************@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/de...cntrlsamp3.asp

http://www.vb-tips.com/default.aspx?...f-04dfd3b31b2b

http://support.microsoft.com/default...b;en-us;308063

Ken
-------------------
"Paul" <te**@tester.com> wrote in message
news:%2****************@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



Mar 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.