Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get the web content with different encodings 2 28
C# Json POSt to Rest API 4 37
Server Error 11 47
Close form "before" open 3 27
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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

14 Experts available now in Live!

Get 1:1 Help Now