Solved

ComboBox1 Undo method???

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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