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

x
?
Solved

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

Posted on 2005-05-06
3
Medium Priority
?
337 Views
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
         ClearScreen(Me)
         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
                    ctl.ResetText()
                End If
        Next
     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?
0
Comment
Question by:cswebdev
  • 2
3 Comments
 
LVL 4

Expert Comment

by:gdexter
ID: 13947743

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

  Me.ComboBox.SelectedIndex = Me.ComboBox.FindString("NO")
0
 
LVL 4

Accepted Solution

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

Author Comment

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

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