Solved

How do I implement the backward and forward (the 2 arrows buttons) in a window's form?

Posted on 2006-07-17
3
196 Views
Last Modified: 2011-09-20
Are there contols or sample code avaiable to implement this?  I'm coding a form with treeview on left and listview on right of a container control.  It's like the Active Directory's computer, user and groups console.  The backward and forward button would change the display of the Treeview and the Listview to previous or forwarded user's selected node.

Thanks.
0
Comment
Question by:lapucca
3 Comments
 
LVL 14

Expert Comment

by:jjardine
ID: 17127854
I have not created this functionality but here is an idea of how you could do it.  

Create an array or arraylist that holds the list of tree nodes that the user clicks on.
Store the index that the user is currently on.

As the user selects the nodes,   Add them to the array and increment the index.  

When the user clicks the back button then subtract 1 from the index and select that node.  

When the user clicks the forward button then add 1 to the index and select that node.  

Hope that helps with an idea for how to solve this.
0
 

Accepted Solution

by:
martin75a earned 500 total points
ID: 17128163
Some code how to accomplish it:

using System.Collections;

...

private ArrayList backList = new ArrayList();
private ArrayList forwardList = new ArrayList();

...

(add two buttons, backButton and forwardButton, and in constructor:)
backButton.Enabled = false;
forwardButton.Enabled = false;

...

private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
{
forwardList.Clear();
forwardButton.Enabled = false;
backList.Add(e.Node);
backButton.Enabled = true;
// code to update the items in the listview
// ...
}

private void backButton_Click(object sender, EventArgs e)
{
TreeNode node = (TreeNode)backList[backList.Count - 1];
backList.Remove(node);
if (backList.Count == 0)
{
backButton.Enabled = false;
}
forwardList.Add(node);
forwardButton.Enabled = true;
treeView.SelectedNode = node;
treeView_AfterSelect(treeView, new TreeViewEventArgs(node));
}

private void forwardButton_Click(object sender, EventArgs e)
{
TreeNode node = (TreeNode)forwardList[0];
forwardList.Remove(node);
if (forwardList.Count == 0)
{
forwardList.Enabled = false;
}
backList.Add(node);
backButton.Enabled = true;
treeView_AfterSelect(treeView, new TreeViewEventArgs(node));
}


This is to get you started, you may want to add more checks to prevent errors.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query datatable in LINQ 6 39
Duplicate a row 2 33
c# if statement weird reaction 3 29
Performance  Html.BeginForm vs jQuery 3 15
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now