Solved

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

Posted on 2006-07-17
3
205 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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