Solved

Clearing a combobox

Posted on 2009-06-29
9
274 Views
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?

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
9 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
have you tried: cbxDepartment.SelectedItem = -1
0
 
LVL 2

Assisted Solution

by:Xygxag
Xygxag earned 200 total points
Comment Utility
Try cbxDepartment.SelectedIndex = -1
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 300 total points
Comment Utility
Correct way is:
cbxDepartment.SelectedItem = Nothing
or
cbxDepartment.SelectedIndex = -1

0
 

Author Closing Comment

by:Mr_Fulano
Comment Utility
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!
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 69

Expert Comment

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

Expert Comment

by:Jaime Olivares
Comment Utility
eric,

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

MSDN documentation states:
SelectedItem:
The object that is the currently selected item or nullNothingnullptra null reference (Nothing in Visual Basic) if there is no currently selected item.
SelectedIndex:
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.



0
 
LVL 69

Expert Comment

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

Expert Comment

by:Jaime Olivares
Comment Utility
it is not the same solution:

emoreau:
 cbxDepartment.SelectedItem = -1
Xygxag:
 cbxDepartment.SelectedIndex = -1
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
my mistake. sorry
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now