Solved

ComboBox1 Undo method???

Posted on 2003-12-02
4
353 Views
Last Modified: 2008-03-10
Hi,

thanks for clicking,

Converted over from Access 2000 to vb.net

In Access had a method that could undo anything typed into the ComboBox with Combo.Undo

Know there is a Undo method for a textbox in vb.net
Is there one for ComboBox, or does anybody know a good work around??

Thanks
Stuart
0
Comment
Question by:StuartK
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9860922
AFAIK the ComboBox does not have an Undo method.  You can code this by keeping track of changes in to the combo box:  adding deleted values, deleting added values, etc.
0
 

Author Comment

by:StuartK
ID: 9867123
Hi TheLearnOne,

What do you mean by "adding deleted values, deleting added values, etc."

I've tried to stick the changed text into an array within the KeyDown event by using

ComboText(i) = Combo1.Text
i =i +1

And then use ComboText(0) to access original text in Combo1. And reset i to 0.

Is this the essence of what your getting at??

Stuart
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 50 total points
ID: 9867301
Here is a small example of what I mean.  I created a form with 1 textbox (TextBox1), 1 combo box (ComboBox1), and 3 buttons (buttonAdd, buttonDelete, buttonUndo).  There is a structure to keep track of the text, action type, and the item index.  It uses a stack to push/pop the undo actions.  When adding/deleting items with the combo box, push action information.  With undo, pop the last action, and restore the item back to its original position.

  Private Enum ActionTypeEnums
      AddItem
      DeleteItem
   End Enum

   Private Structure UndoAction
      Public Action As ActionTypeEnums
      Public UndoText As String
      Public Index As Integer
   End Structure

   Private m_UndoStack As New Stack


 
   Private Sub buttonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAdd.Click

      Dim newAction As UndoAction

      Me.ComboBox1.Items.Add(Me.TextBox1.Text)

      newAction.Action = ActionTypeEnums.AddItem
      newAction.UndoText = Me.TextBox1.Text
      newAction.Index = Me.ComboBox1.Items.Count - 1

      m_UndoStack.Push(newAction)

   End Sub

   Private Sub buttonUndo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonUndo.Click

      Dim oldAction As UndoAction

      If m_UndoStack.Count > 0 Then

         oldAction = CType(m_UndoStack.Pop, UndoAction)

         If oldAction.Action = ActionTypeEnums.DeleteItem Then

            Me.ComboBox1.Items.Insert(oldAction.Index, oldAction.UndoText)

         End If

      End If

   End Sub


   Private Sub buttonDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonDelete.Click

      Dim newAction As UndoAction

      newAction.Action = ActionTypeEnums.DeleteItem
      newAction.UndoText = CStr(Me.ComboBox1.Items(0))
      newAction.Index = 0

      Me.ComboBox1.Items.RemoveAt(0)

      m_UndoStack.Push(newAction)

   End Sub
0
 

Author Comment

by:StuartK
ID: 9884241
Hi TheLearnedOne,

Sorry for late reply. Got distracted, and only noticed still open when I returned to EE

First of all I'm very priveleged to have you answer my question, especially when I'm a small time programmer just starting out, who can only afford 50 points per question, otherwise I run out of points. No.6, soon to be No.4 in this years list and you take time to answer my question. Thank you.

The last email did go above my head a little bit. Just to feed back the way I got around it. I set a Global variable and set it to Combo.Text property in the Combo_Enter event. Then if Item was NotInList (using code that checks .Text against each value in list) within Validating event, it then reverted to the Global string.

Hope I haven't bored you, but I feel it's bad manners to simply ignore and not have the courtesy to let them know how it was resolved.

Thanks you again, Stuart
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now