Solved

Cancelling a remove

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

16 Experts available now in Live!

Get 1:1 Help Now