Click here to Skip to main content
15,898,538 members
Home / Discussions / C#
   

C#

 
Questionbuttons click event is fire accurately but radiobuttonlist controls SelectIndexChanged event is not fired help me !! Pin
jyoti_goel27-Mar-09 7:33
jyoti_goel27-Mar-09 7:33 
AnswerRe: buttons click event is fire accurately but radiobuttonlist controls SelectIndexChanged event is not fired help me !! Pin
Xmen Real 27-Mar-09 8:37
professional Xmen Real 27-Mar-09 8:37 
Question[Message Deleted] Pin
Ibrahim Bello27-Mar-09 6:56
Ibrahim Bello27-Mar-09 6:56 
AnswerRe: Change GridView Column Header Text Pin
fly90427-Mar-09 7:04
fly90427-Mar-09 7:04 
JokeRe: [Message Deleted] Pin
musefan27-Mar-09 7:41
musefan27-Mar-09 7:41 
GeneralRe: [Message Deleted] Pin
Ibrahim Bello27-Mar-09 8:28
Ibrahim Bello27-Mar-09 8:28 
GeneralRe: [Message Deleted] Pin
#realJSOP27-Mar-09 8:42
professional#realJSOP27-Mar-09 8:42 
QuestionProgmatically Creating TreeNodes and Child Nodes [modified] Pin
maxatlis27-Mar-09 5:44
maxatlis27-Mar-09 5:44 
Hi guys

I’m at my wits end with TreeNodes. Dead | X|

What i'm trying to do, to me is very simple. But for some reason I just can't get my head around it! Sigh | :sigh:

I’m currently working on a project where basically I’m splitting a Url address into a string array and creating each node and child node from the url segments (just like the Windows Explorer.)

\\ this is the plan

1) step through each url
string url1 = @"www.somedomain.com\home\about_us.aspx";
string url2 = @"www.somedomain.com\home\contact_us.aspx";
string url3 = @"www.somedomain.com\home\main.aspx";

2) split the current url into sections

3) process the url sections and create new nodes and child nodes or merge nodes if needed

4) output results


the final output I'm trying to get...

+ www.somedomain.com
_+ home
___+ about_us.aspx
___+ contact_us.aspx
___+ main.aspx


but in short i'm getting something like...

+ www.somedomain.com
_+ home
___+ about_us.aspx
___+ contact_us.aspx
___+ main.aspx
_+ home
___+ about_us.aspx
___+ contact_us.aspx
___+ main.aspx


Looking at the code below, Is there another way around this problem or am I just being stupid???


Any help would be very much appreciated. Please feel free to rip the hell out of my coding as I've kind of lost the plot!

Thanks again! Smile | :)


<pre>private void Form1_Load(object sender, EventArgs e)
{
TreeNode treeNode = new TreeNode();
treeView1.Nodes.Add(treeNode);
treeView1.PathSeparator = "\\"

// Add first url address
BuildNodes(treeNode,@"1\2\3\4\5\6\7");

// Add the next url address merging duplicate folders together...
BuildNodes(treeNode, @"1\2\4\5\6");
}</pre>

<pre>private void BuildNodes(TreeNode treeNode, string address)
{
string[] add = SplitNodes(address);

int max = add.Length;
string key = String.Empty;

TreeNode[] treeNodes = new TreeNode[max];
key = add[0];

treeNodes[0] = treeNode;
treeNodes[0].Text = add[0];
treeNodes[0].Name = key;

for (int i = 1; i < max; i++)
{
key = GetKey(key, add[i]);

treeNodes[i] = new TreeNode();
treeNodes[i].Text = add[i];
treeNodes[i].Name = key;

TreeNode[] tns = treeNodes[i - 1].Nodes.Find(treeNodes[i].Name, true);

// if node exists skip it else add the new node
if (tns.Length == 0)//if
{
treeNodes[i - 1].Nodes.Add(treeNodes[i]);
}
}

}</pre>

<pre>private string GetKey(string key, string value)
{
string delimiter = treeView1.PathSeparator;

if (key == String.Empty)
return value;
else
return String.Format(@"{0}{1}{2}", key, delimiter, value);
}</pre>

<pre>private string[] SplitNodes(string nodeString)
{
char[] delimiter = treeView1.PathSeparator.ToCharArray();
return nodeString.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
}
</pre>

<div class="ForumMod">modified on Friday, March 27, 2009 12:01 PM</div>
AnswerRe: Progmatically Creating TreeNodes and Child Nodes [modified] Pin
musefan27-Mar-09 6:02
musefan27-Mar-09 6:02 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:11
maxatlis27-Mar-09 6:11 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:27
maxatlis27-Mar-09 6:27 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
musefan27-Mar-09 6:34
musefan27-Mar-09 6:34 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:44
maxatlis27-Mar-09 6:44 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
musefan27-Mar-09 6:49
musefan27-Mar-09 6:49 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 7:10
maxatlis27-Mar-09 7:10 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
fly90427-Mar-09 7:54
fly90427-Mar-09 7:54 
AnswerRe: Progmatically Creating TreeNodes and Child Nodes Pin
Ian Shlasko27-Mar-09 9:58
Ian Shlasko27-Mar-09 9:58 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 13:20
maxatlis27-Mar-09 13:20 
AnswerHow To: - Progmatically Creating TreeNodes and Child Nodes [Answer] Pin
maxatlis27-Mar-09 14:37
maxatlis27-Mar-09 14:37 
QuestionOracle + #C DataBase Picture Pin
E_Gold27-Mar-09 5:17
E_Gold27-Mar-09 5:17 
QuestionNew Line VS2005 Installer's BodyText Pin
jp2code27-Mar-09 5:12
professionaljp2code27-Mar-09 5:12 
Questiondatabase in sql Pin
Mangesh Tomar27-Mar-09 4:39
Mangesh Tomar27-Mar-09 4:39 
AnswerRe: database in sql Pin
musefan27-Mar-09 4:47
musefan27-Mar-09 4:47 
GeneralRe: database in sql Pin
Mangesh Tomar27-Mar-09 5:41
Mangesh Tomar27-Mar-09 5:41 
GeneralRe: database in sql Pin
musefan27-Mar-09 5:48
musefan27-Mar-09 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.