ComboBox1 Undo method???

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
StuartKAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
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
StuartKAuthor Commented:
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
Bob LearnedCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StuartKAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.