473,387 Members | 1,760 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,387 software developers and data experts.

I am trying to make a data aware treeview

I am trying to create a TreeView control that works with an ADO Dataset
DataTable or the new BindingSource stuff in .NET 2.0 to build a Treeview
that is populated.

This is what I came up with so far... I can't run it yet because I don't
have the DataTable source... I still want to get some sort of assessment as
to whether I am heading in the right direction. Here is the code:
================================
using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Data;

namespace WindowsApplication1

{

class NewTree:System.Windows.Forms.TreeView

{

// the data used to build the treeview

protected System.Data.DataTable m_Table;

private System.Data.DataColumn m_KeyColumn;

private System.Data.DataColumn m_ParentKeyColumn;

private System.Data.DataColumn m_TextKeyColumn;

private System.Windows.Forms.TreeNode m_TreeNode;

// Constructor for the class

public NewTree(DataTable m_Table,
string m_KeyColumnName, //name of the primary key column

string m_ParentKeyColumnName, //name of the parent id column

string m_TextColumnName, // name of the column used for text.

int m_StartValue)

{
// Initialize references to columns needed

m_KeyColumn = m_Table.Columns[m_KeyColumnName];

m_ParentKeyColumn = m_Table.Columns[m_ParentKeyColumnName];

m_TextKeyColumn = m_Table.Columns[m_TextColumnName];

// Set initial table filter

string m_filterClause;

m_filterClause = m_ParentKeyColumnName + " = " + m_StartValue.ToString();

m_Table.Select(m_filterClause);

// turn off screen refresh

this.BeginUpdate();

// add relevant root nodes

foreach (DataRow m_thisRow in m_Table.Rows)

{

m_TreeNode = new TreeNode();

m_TreeNode.Tag = m_thisRow.ItemArray.GetValue(m_KeyColumn.Ordinal() );

m_TreeNode.Text = m_thisRow.ItemArray.GetValue(m_TextKeyColumn.Ordin al());

// recursive data function should build a full branch of nodes

buildBranch(m_TreeNode);

this.Nodes.Add(m_TreeNode);
}

// turn on screen refresh

this.EndUpdate();

}

/// <summary>

/// buildBranch is an attempt to build a recursive function to

/// build nodes for a treeview control.

/// I am making the assumption that as a object m_thisNode gets passed

/// by reference. Thus the parent level object should be modified with

/// all its children by the time the root node is added to the treeview

/// nodes collection.

/// </summary>

/// <param name="m_thisNode"></param>

private void buildBranch(TreeNode m_thisNode)

{

TreeNode m_InnerNode;

// set up new filter for table

m_filterClause = m_ParentKeyColumnName + " = " + m_thisNode.Tag.ToString();

m_Table.Select(m_filterClause);

// add child nodes

foreach (DataRow m_thisRow in m_Table.Rows)

{

m_InnerNode = new TreeNode();

m_InnerNode.Tag = m_thisRow.ItemArray.GetValue(m_KeyColumn.Ordinal() );

m_InnerNode.Text = m_thisRow.ItemArray.GetValue(m_TextKeyColumn.Ordin al());

buildBranch(m_InnerNode);

m_thisNode.Nodes.Add(m_InnerNode);

}

}

}

}

==============================

When I dragged the dataset into the application I expected to see references
to a DataSet and DataTables. instead I am seeing BindSources and stuff. I
am not sure how to translate back to the DataTable in order to even test
this.

Your suggestions are welcome.

Mar 25 '06 #1
0 1626

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

Similar topics

1
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hello, I am working on Treeview control. I want that, user create tree according to his requirement, can add topic under any node. Then just click update and that treeview data to be stored in...
1
by: NagaKiran | last post by:
Hi I am able to display XML contents in a treeview. But I am unable to create an XML file using treeview data. I have a TreeView control wich contains many levels of data.I want create write...
2
by: Jack | last post by:
Hello, I am trying use a TreeView with checkboxes. I would like to check more than one node and allow all child nodes of selected nodes to be checked or unchecked with the parent is checked. ...
5
by: lanem | last post by:
I want to display some drill-down data with a datagrid look. I can get the exact functionality I want with a treeview, but I don't like the way the treeview looks and formats the data. I want a...
4
by: Xenomorph | last post by:
I have a program where you click an item on the TreeView on the left, and then work with whatever pops up on the right. There are many entries on the TreeView, and when you click something on the...
1
by: echuck66 | last post by:
Hi, I have a Winforms 2.0 project that I'm working on that involves populating a treeview control from data contained in a fairly large dataset that has to be refreshed periodically. I have no...
0
by: =?Utf-8?B?SmVmZiBHYW8=?= | last post by:
Hi, I am working on an asp.net web application that uses treeview control to display hierarchical data from an xml data source. When I changed the xml data source the treeview doesn’t update...
5
by: Max2006 | last post by:
Hi, I have a TreeView and this is my node style: <asp:TreeNodeStyle ForeColor = "#000000" Font-Size="9px" Font-Bold="false" Width="100px" NodeSpacing="3px" /> The problem is the expand...
3
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I have a TreeView control that I am populating with a lot of data. I have been asked to expand the nodes so management can quickly access the individual elements. This is easy to do with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.