473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

loading a treeeview from Database

Hi,

I am trying to load my items from Database to a Treeview but i have faild

My table contains id, parentId, nodeName like following:

(1 , 1 RootNode)

(2 , 2 , ParentNode)

(3, 2 , Child_for_2)

(4, 4 , AnotherParent)

(5 , 2 , anotherChild_for_2)

(6 , 4 , Child_for_4)

My problem is ,how i can create a treeview from this rows ( need some code).

here is a bit of my code what i have been trying for 6 hours.

try
{
treeView.BeginUpdate();
DataSet DS = new DataSet();
DS = MyWebService.LoadTreeViewFromDB();
if (DS != null)
{
TreeNode Root = new TreeNode("Taxonomy");
Root.Tag = 1;
treeView.Nodes.Add(Root);
TreeNode ParentNode = null;

foreach (DataRow DR in DS.Tables["folksonomy"].Rows)
{
TreeNode NewNode = new TreeNode();

if (DR["id"].ToString() == DR["parentid"].ToString())
{
NewNode.Text = DR["nodename"].ToString();
NewNode.Tag = DR["id"].ToString();
Root.Nodes.Add(NewNode);
}

else
{
foreach (DataRow ChildDataRow in DS.Tables["folksonomy"].Rows)
{
if (ChildDataRow["id"].ToString() == DR["parentid"].ToString())
{
I dont know what i should write here
}
}
}

}
}
May 10 '06 #1
1 1569
Hello Medes,

See sample there http://www.codeproject.com/cs/miscct...02#xx1169975xx

BTW, why not to use XML for this, like over there http://support.microsoft.com/default...b;en-us;308063
M> Hi,
M>
M> I am trying to load my items from Database to a Treeview but i have
M> faild
M>
M> My table contains id, parentId, nodeName like following:
M>
M> (1 , 1 RootNode)
M>
M> (2 , 2 , ParentNode)
M>
M> (3, 2 , Child_for_2)
M>
M> (4, 4 , AnotherParent)
M>
M> (5 , 2 , anotherChild_for_2)
M>
M> (6 , 4 , Child_for_4)
M>
M> My problem is ,how i can create a treeview from this rows ( need some
M> code).
M>
M> here is a bit of my code what i have been trying for 6 hours.
M>
M> try
M> {
M> treeView.BeginUpdate();
M> DataSet DS = new DataSet();
M> DS = MyWebService.LoadTreeViewFromDB();
M> if (DS != null)
M> {
M> TreeNode Root = new TreeNode("Taxonomy");
M> Root.Tag = 1;
M> treeView.Nodes.Add(Root);
M> TreeNode ParentNode = null;
M> foreach (DataRow DR in DS.Tables["folksonomy"].Rows)
M> {
M> TreeNode NewNode = new TreeNode();
M> if (DR["id"].ToString() == DR["parentid"].ToString())
M> {
M> NewNode.Text = DR["nodename"].ToString();
M> NewNode.Tag = DR["id"].ToString();
M> Root.Nodes.Add(NewNode);
M> }
M> else
M> {
M> foreach (DataRow ChildDataRow in DS.Tables["folksonomy"].Rows)
M> {
M> if (ChildDataRow["id"].ToString() == DR["parentid"].ToString())
M> {
M> I dont know what i should write here
M> }
M> }
M> }
M> }
M> }
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ram | last post by:
We are trying to load text tab delimited files into SQL server using informatica 5.1 version. The text files are FTPed to a local server and then files are moved to applicable folder before...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
4
by: Jonas Nilsson | last post by:
How can i show a "Wait while loading..." text on my aspx page while loading data into a datagrid from a database. /Jonas
4
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
5
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
We have a page that is loading very slow. There is not a lot of data, not a lot of users are connected at the same time and the page does not produce an error, so I am not sure where to start to...
2
by: Vili | last post by:
Hi all I am having problems with creating an functional questionnaire with asp.net 2.0 and MSSQL 2005 database. I have a table with field id (key & auto int), clientId (int), QuestionId...
1
by: rshivaraman | last post by:
Hi All: I need to make my database unavailable when i am loading the db. This happens daily and the db is not connected to any online app, to make the app unavailable. It is queried thru an...
1
by: =?Windows-1252?Q?Tor_B=E5dshaug?= | last post by:
BlankHi, I am having trouble loading assemblies from the database in my ASP.NET app. I have a default.aspx in my app that is served from a database via a custom virtual path provider. This works...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.