Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How do I reset a combobox to a specific item in the items collection?

Posted on 2005-05-06
Medium Priority
Last Modified: 2010-04-23
I have a form that is used to gather search criteria.  One of the controls is a button to clear all the fields to start a new search, another control is a combo box that is populated from the items collection of "NO", "YES", "MAYBE", "DON'T KNOW".  Because 95% of the time the answer is "NO", the user wants that to be the default value and it will only be changed rarely.   Here is what I have so far:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         Me.ComboBox.Text = "No"
     End Sub

    Public Sub ClearScreen(ByVal FormName As Form)
        Dim ctl As Control
        For Each ctl In FormName.Controls()
                If ctl.Tag Like "Init*" Then
                End If
     End Sub

This works great on form1_load.  My problem is when the user clicks the "Clear" button and I execute the same code I do on form1_load, the combobox is now empty.  How do I get it to display the "NO" again?
Question by:cswebdev
  • 2

Expert Comment

ID: 13947743

  As long as you are not clearing the combo box you can do this:

  Me.ComboBox.SelectedIndex = Me.ComboBox.FindString("NO")

Accepted Solution

gdexter earned 300 total points
ID: 13947765
Put the above code at the end of the ClearScreen method

Author Comment

ID: 13947794
I knew it had to be something simple I was missing!  Thank you very much.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

572 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