473,405 Members | 2,171 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,405 software developers and data experts.

Messy TreeView Results

Hi.

I am getting odd treeview results and hope you can help.

I am parsing a string, "x/y/z", turning it into an array (that
always seems to start with an empty string) and then
using the elements of that array to populate a single tree.
The first non-empty element is the root, the last is a file -
everything in between is a folder.

THE PROBLEM is that I am getting the root with an
empty folder as one tree, then the next element with
all the other nodes below it.

So,

array [1], [2], [3], [4]

Should produce the following results:

-- [1] (root folder)
-------[2] (folder)
------------[3] (folder)
------------[4] (file)

But, I am getting

--[1] (root folder)
------[?] (empty folder with no name)

--[2] (folder)
------[3] (folder)
------[4] (file)

And this pattern repeats down the grid.

Below is the code, I would really appreciate some
clear input help here. Thanks.

public void OnDataBinding(object sender, EventArgs e)
{

int count = 0;

TreeView tree = (TreeView)sender;
GridViewRow container = (GridViewRow)tree.NamingContainer;

if (storedNodes.Count != 0)
{

string path = storedNodes.Pop().ToString();
string[] arr = path.Split('/');

root = new TreeNode();
root.ImageUrl = "folder.gif";

if (arr[0] != "")
root.Text += arr[0].ToString();
else if (arr[1] != "")
root.Text += arr[1].ToString();

root.SelectAction = TreeNodeSelectAction.SelectExpand;
root.PopulateOnDemand = true;
root.SelectAction = TreeNodeSelectAction.Expand;

for (int i = 1; i <= arr.Length - 1; i++)
{

if (arr[i] != "")
{

TreeNode node = new TreeNode();

if (i != arr.Length - 1)
{

node.ImageUrl = "folder.gif";
node.Text += arr[i].ToString();
node.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.PopulateOnDemand = true;
node.SelectAction =
TreeNodeSelectAction.Expand;

}
else
{

node.ImageUrl = "play.jpg";
node.Text += arr[i].ToString();
node.SelectAction = TreeNodeSelectAction.None;
node.Value = "vBrickTree";
node.SelectAction =
TreeNodeSelectAction.Expand;

}

root.ChildNodes.Add(node);
count++;

}

}

tree.Nodes.Add(root);
}

}
Nov 15 '07 #1
11 1489
"pbd22" <du*****@gmail.comwrote in message
news:c3**********************************@f13g2000 hsa.googlegroups.com...
for (int i = 1; i <= arr.Length - 1; i++)
What happens if you use:

for (int i = 0; i < arr.Length; i++)
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 15 '07 #2

Hi.

Thanks for responding.

I get an "InxedOutOfBoundsException" :

for (int i = 1; i <= arr.Length; i++)
{

if (arr[i] != "") < --- EXCEPTION THROWN HERE, WHERE
i = 4
{
The Current Range is:

[0] ""
[1] "Utah"
[2] "Jackson"
[3] "Climbing.wmv"

Nov 15 '07 #3
"pbd22" <du*****@gmail.comwrote in message
news:22**********************************@e4g2000h sg.googlegroups.com...
Thanks for responding.

I get an "InxedOutOfBoundsException" :

for (int i = 1; i <= arr.Length; i++)
With the greatest of respect, what happens if you actually try the code I
suggested...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 15 '07 #4
On Nov 15, 1:40 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"pbd22" <dush...@gmail.comwrote in message

news:22**********************************@e4g2000h sg.googlegroups.com...
Thanks for responding.
I get an "InxedOutOfBoundsException" :
for (int i = 1; i <= arr.Length; i++)

With the greatest of respect, what happens if you actually try the code I
suggested...?

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Sorry, I did try the code you suggested.
You are talking about the 1, right? I had
it at zero but played around and then, sloppily,
cut and paste the "played around" version
here. But, the result is as i said - out of bounds
(when i = 0 or 1)..

Thanks again.
Nov 15 '07 #5
"pbd22" <du*****@gmail.comwrote in message
news:b5**********************************@v4g2000h sf.googlegroups.com...
You are talking about the 1, right?
Not specifically...

for (int i = 0; i < arr.Length; i++)
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 15 '07 #6
On Nov 15, 2:52 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"pbd22" <dush...@gmail.comwrote in message

news:b5**********************************@v4g2000h sf.googlegroups.com...
You are talking about the 1, right?

Not specifically...

for (int i = 0; i < arr.Length; i++)

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
i am sorry. i am doing this in between
meetings and am making more of a
mess than I started with.

I did i=0 as you suggested. for an
array from [0] to [3], where arr.Length = 4
and i=0 I get an array out of bounds
exception.

Thanks for being patient.
Nov 15 '07 #7
"pbd22" <du*****@gmail.comwrote in message
news:e8**********************************@b32g2000 hsa.googlegroups.com...
I did i=0 as you suggested. for an
array from [0] to [3], where arr.Length = 4
and i=0 I get an array out of bounds
exception.

Thanks for being patient.
There must be an error somewhere else, then...

Arrays are zero-based by default...

So, if your array has four elements, the first will be at index [0] etc...

Have you tried stepping through the code...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 15 '07 #8
This seems to work.
Does it look right to you?

I am getting the nodes I want but the
tree is not displaying as a stair case, more of
a pyramid standing on its bottom edge.

string[] arr = path.Split('/');

for (int i = 0; i <= arr.Length -1; i++)
{

if (arr[i] != "")
{

child = new TreeNode();
child.ImageUrl = "folder.gif";
child.Text += arr[i].ToString();
child.PopulateOnDemand = true;
child.ChildNodes.Add(child);
tree.Nodes.Add(child);

}
}
Nov 15 '07 #9
"pbd22" <du*****@gmail.comwrote in message
news:d8**********************************@f3g2000h sg.googlegroups.com...
This seems to work.
Does it look right to you?
Pretty much.
for (int i = 0; i <= arr.Length -1; i++)
I guess it comes down to preference, but I was always taught that

for (int i = 0; i < arr.Length; i++)

gave better performance because it didn't need to check whether the
incrementing variable was EITHER less than OR equal to the upper boundary of
the array, and didn't have to perform the additional calculation of
subtracting 1 from the upper boundary of the array...

Probably makes no difference to IL, though...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 15 '07 #10
it's odd.
In Firefox, the folders are in a perfect vertical line.
In IE, sort of a pyramid on its side.

I think maybe the former child is not a subset
of the previous child?

Nov 15 '07 #11
in other words, why am I need seeing the staircase effect of treeview?
Nov 15 '07 #12

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

Similar topics

4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
0
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A...
2
by: Aaron Corcoran | last post by:
I posted this under the webcontrols area as well, however, I didn't receive any feedback, so please pardon my redundant post. Dear Group, My coworker has been working on a project that uses...
1
by: Edwin Knoppert | last post by:
I'm using a simple treeview for helpsystem. The treeview is on a masterpage, right beside it it has the container. The user uses the treeview to navigate to helppages using this masterpage. But on...
0
by: Edwin Knoppert | last post by:
I'm using a simple treeview for helpsystem. The treeview is on a masterpage, right beside it it has the container. The user uses the treeview to navigate to helppages using this masterpage. But on...
2
by: Loopsludge | last post by:
Using ASP.NET 2005/C# flavor, I need to dynamically populate a TreeView control from the results of a SQL Server 2005 query. Clicking on the end leaf of the tree will need to yield some details...
2
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement...
0
by: noneya22 | last post by:
I want to use a TreeView control as a one-level, vertical navigation menu. I'm using this control currently with a SiteMapDataSource and .sitemap file. I've written code that associates an image...
1
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m having a couple of problems using the TreeView control on a windows form. I feel as if I’m missing something very obvious, but I not seeing it! Any suggestions would be appreciated. 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.