Solved

Cancelling a remove

Posted on 2006-07-19
5
348 Views
Last Modified: 2010-04-16
I have a list of information stored in a list box.

I have a remove and remove all buttons. I also have a Finish and a Cancel.

What I was looking to do was have cancel revert the changes in the list box.The main example that I can give is when you actually have removed certain elements from the list box. You then decide to click cancel, but it doesnt restore the list box.

Any ideas on how best to handle and implement this?
0
Comment
Question by:directxBOB
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:nickhoggard
ID: 17144002
Hi,

I'm not entirely sure what you are asking for here.  Is the cancel supposed to act as an undo, adding the last removed item back in, or is it supposed to refresh the listbox to its original state?   Also, what sort of objects are being stored in the list box?

Cheers

Nick
0
 

Author Comment

by:directxBOB
ID: 17144133
At the moment the list box is just string objects but I will replace them down the line.

Well I can either take 2 roots, when I remove something I can store it in a cache until finished is clicked Which is ideal, or I can refresh back to the original state. The second method is fine as well. just once data is not lost when canceled.
0
 

Author Comment

by:directxBOB
ID: 17144148
The way I was thinking of doing it was to all the user to select what they want to remove, or to remove all.

Then have flags, if the user hits cancel nothing is done, but if the user hits finished it checks these flags and removes whats been requested.
0
 
LVL 5

Accepted Solution

by:
nickhoggard earned 500 total points
ID: 17144651
Not sure if this is exactly what you were after, but the only thing I can think of would be to either a) cache a clone of  the whole dataset when you set the DataSource property, b) cache the removed items as discuessed above.  I'd probably go with b) myself.

Something like:

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1 {
    class ListBoxEx : ListBox {

        System.Collections.ArrayList cvobjRemovedItems = new System.Collections.ArrayList();
        public void RemoveAt(int intIndex) {
            cvobjRemovedItems.Add(this.Items(intIndex));
            this.Items.RemoveAt(intIndex);
        }

        public void Cancel() {
            foreach (object obj in cvobjRemovedItems) {
                this.Items.Add(obj);
            }
        }

        public void ClearCache() {
            cvobjRemovedItems.Clear();
        }

    }
}

Hope this gets you started.

Cheers

Nick
0
 

Author Comment

by:directxBOB
ID: 17151238
Dumb question but Im doing this:

      foreach (object obj in RemoveList)
      {
        int selectedIndex = RemoveList.????
      }


How do I actually get the value that I am currently on in RemoveList out? I am putting in all selected indexes. so Im really just wondering how I get the values out.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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