?
Solved

How to set ComboBox that has DropDownList style to empty after the Form is displayed for the first time?

Posted on 2005-03-14
6
Medium Priority
?
218 Views
Last Modified: 2010-04-23
i tried using ComboBox1.SelectedIndex = -1 in the Form Load Events but it did not work, the ComboBox1 still displaying Index 0

thanks
0
Comment
Question by:yukisu
[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
  • 2
6 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 13538363
If you just want to have the combobox text area emtpy change too dropdown and not dropdownlist
0
 
LVL 27

Expert Comment

by:planocz
ID: 13538433
If you want to clear the whole list then

 ComboBox1.Items.Clear()
0
 
LVL 1

Expert Comment

by:UnFiRe
ID: 13541206

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Text = Nothing
        ComboBox1.SelectedItem = Nothing
    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yukisu
ID: 13546321
planocz,
ComboBox1.Items.Clear() does not work in Form_Load

UnFiRe,
ComboBox1.Text = Nothing
ComboBox1.SelectedItem = Nothing
also do not set the dropdownlist to empty

i want to set the dropdownlist to empty so the user is force to select one value from the list, thus the default value for the dropdownlist must be blank.
i can do this by setting ComboBox1.SelectedIndex = -1, but only after i called it when the form already loaded.
setting ComboBox1.SelectedIndex = -1 in the form_load event does not work
so when the form open for the first time, the dropdownlist index always go back to index 0

anyone know how to set the dropdownlist index to -1 (empty/blank value) on Form_Load Event?

thanks
0
 
LVL 1

Accepted Solution

by:
UnFiRe earned 200 total points
ID: 13549366
yukisu,
The ComboBox.SelectedItem = Nothing MUST work
If it does not, there must be a statement that is executed AFTER the "ComboBox.SelectedItem = Nothing" statement that selects an item in your combobox.
ComboBox1.SelectedIndex = -1 also MUST work. The reason you are getting something selected after even these statements have been executed, is
1. you have some statements being executed after those above that select an item in your combobox
2. your combobox is bound to a datasource

if it is option 2, you can use this approach:
Instead of setting your datasource and displaymember in the design view, set it programmatically on the DropDown event
Something like this

    Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
        ComboBox1.DataSource = me.DataSet1.Table1
        ComboBox1.DisplayMember = "column1"
    End Sub

In design view set the datasource to None
On form load event or in design view you can set the text of combobox to display when it is first loaded
such as "Select User"
0
 

Author Comment

by:yukisu
ID: 13558097
UnFiRe,
nice solution, but i cannot set the text for the ComboBox since it is a DropDownList

thanks a lot
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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