Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,939 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,413 people online right now. Registration is fast and FREE... Join Now!




ComboBox open new Form

 
Reply to this topicStart new topic

ComboBox open new Form

quakeworld2007
11 Dec, 2007 - 08:06 PM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 44


My Contributions
I have a combox and I want it to open up a new form when users double-click on the combo box so that they can add new choices to the combobox. Is this possible in vb.net I added some code like you would if the combobox was a button, but all it did was focused on the combobox when I double clicked on it.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: ComboBox Open New Form
11 Dec, 2007 - 09:21 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yeah this is because the combobox doesn't respond to mousedoubleclick events. But you can simulate this behavior through the mouseclick event and testing if another click has happened in the time span of the first click quick enough to be considered a double click. It goes like this...

CODE

' Record the last click with the current time
Dim lastClick As Date = Now

Private Sub ComboBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseClick
        ' Test if in the last time plus the milliseconds it takes for a double click
        ' there was another click, activate the code (there was a double click)
        If Now < lastClick.AddMilliseconds(SystemInformation.DoubleClickTime) Then

            ' Create our second form and show it modal
            Dim form As New Form2
            form.ShowDialog()

        End If

        ' Record the last click as now again
        lastClick = Now
End Sub


We show the second form modally, so in that form we have a textbox and a button which adds whatever is in the textbox to the combobox on form1 and hides itself using a button.

The rest is history. Enjoy the code!

"At DIC we be double click simulating code ninjas!" decap.gif

This post has been edited by Martyr2: 11 Dec, 2007 - 09:22 PM
User is offlineProfile CardPM
+Quote Post

quakeworld2007
RE: ComboBox Open New Form
12 Dec, 2007 - 07:18 AM
Post #3

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 44


My Contributions
Thanks for the help works like a charm now.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month