Solved

ComboBox1 Undo method???

Posted on 2003-12-02
4
354 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

15 Experts available now in Live!

Get 1:1 Help Now