|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Changes made to the table in the IntroductionLike so many others, when I needed to use the The purpose of this article is to show you how to develop a Main Objective
Class StructureThere are two classes in the project, the Loading the DataLet's have a look at the private void LoadTree()
{
if (this._datasource != null)
{
Clear();
//Iterate throght the DataRow Collection
foreach (DataRow dr in this._datasource.Rows)
{
TreeNodeBound node =
new TreeNodeBound(dr[this._displayMember].ToString());
node.Value = dr[this._valueMember];
node.ParentValue = dr[this._parentMember];
//Add it to the HashTable
_nodesByValueMember.Add(node.Value, node);
}
//Iterate throught the nodes Collection
foreach (TreeNodeBound node in _nodesByValueMember.Values)
{
if (node.ParentValue != _rootParentValue)
{
//look for the parent node
TreeNodeBound parent =
(TreeNodeBound) _nodesByValueMember[node.ParentValue];
//add it to the nodes collection of the parent node
parent.Nodes.Add(node);
}
else
{
//the node is a Root, add it to the root collection
base.Nodes.Add(node);
}
}
}
}
First, I create the nodes and add it to the Because classes in .NET are reference types, the whole tree structure is loaded. By doing this, we avoid doing a Keeping Track of Data ChangesFor that, I subscribe to the events in the //subscribe to datatable events
value.RowDeleting += new DataRowChangeEventHandler(value_RowDeleting);
value.RowChanged += new DataRowChangeEventHandler(value_RowChanged);
There are four possible changes that are taken care of:
Getting/Setting the SelectedValueBoth cases are trouble-free because of the use of the public object SelectedValue
{
get
{
if (this.SelectedNode != null)
{
return ((TreeNodeBound)this.SelectedNode).Value;
}
else
{
return null;
}
}
set
{
if (value != null)
{
this.SelectedNode =
(TreeNodeBound) _nodesByValueMember[value];
}
}
}
SummaryAt first, I came with the idea of a History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||