Solved

ComboBox1 Undo method???

Posted on 2003-12-02
4
358 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
[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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 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