Solved

Cancelling a remove

Posted on 2006-07-19
5
350 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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