Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Cancelling a remove

Posted on 2006-07-19
5
349 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

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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