Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Clearing a combobox

Posted on 2009-06-29
Medium Priority
Last Modified: 2012-05-07
Hi, I'm using VB2005, WinForms. I have a DataGridView and a set of Controls (i.e. Textboxes, ComboBoxes, etc) on one of my Forms. For the ComboBoxes, I load the data from the DataGridView in the following manner, which works fine - no problem there.

cbxDepartment.SelectedItem = dgvUserList.Rows(intRowIndex).Cells("DepartmentName").Value.ToString

However, once a value has been loaded into the "Text" property of the ComboBox, I cannot clear it to a "blank" value. I can replace it by reloading a new value, but I cannot do the following (it has no effect).

cbxDepartment.Text = String.Empty       ' Not working
cbxDepartment.Text = ""            ' Not working either

Is there a way to clear the Text value once the ComboBox has a Text value visible?

Question by:Mr_Fulano
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
LVL 70

Expert Comment

by:Éric Moreau
ID: 24741238
have you tried: cbxDepartment.SelectedItem = -1

Assisted Solution

Xygxag earned 800 total points
ID: 24741242
Try cbxDepartment.SelectedIndex = -1
LVL 55

Accepted Solution

Jaime Olivares earned 1200 total points
ID: 24741287
Correct way is:
cbxDepartment.SelectedItem = Nothing
cbxDepartment.SelectedIndex = -1

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 Closing Comment

ID: 31598161
Both solutions worked. One contributor provided more than one option, which I took into consideration while splitting the points. -- Thank you both for the great help!
LVL 70

Expert Comment

by:Éric Moreau
ID: 24744065
I don't understand why I haven't got any points here since I was the first to propose this solution! Really strange!
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24744299

Maybe you didn't notice but your proposal:
cbxDepartment.SelectedItem = -1
should be:
cbxDepartment.SelectedItndex = -1

MSDN documentation states:
The object that is the currently selected item or nullNothingnullptra null reference (Nothing in Visual Basic) if there is no currently selected item.
A zero-based index of the currently selected item. A value of negative one (-1) is returned if no item is selected.

So, your proposal should work unless by any chance one of the values in combo is -1. But it is against MSDN documentation.

LVL 70

Expert Comment

by:Éric Moreau
ID: 24744501
how come Xygxag who posted the same I did after me got points?
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24745582
it is not the same solution:

 cbxDepartment.SelectedItem = -1
 cbxDepartment.SelectedIndex = -1
LVL 70

Expert Comment

by:Éric Moreau
ID: 24745890
my mistake. sorry

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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