473,721 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clearing items from combobox

Hola

I wanted to kno how to clear the current text that is displayed in my combobox
I am filling it with a query which is run against my database

I have tried this but it not work

Combobox1.text = "

am i using the wrong event
Can someone advise me with correction?
Jul 21 '05 #1
4 2111
I think anyone will have to have additional info to answer your question.
In the simpliest of cases, manually adding the items from the result of the
query, the line of code you illustrated will clear the text of the combo.
Therefore, I have to ask, does your statement that you are filling the combo
with a query, mean that the combo is bound to a query result? If so, where
the Combobox.text = "" instruction located; ie, what event? Are you setting
any other properties of the combo, ie, DisplayMember, etc. I don't know for
sure that I can answer the question, but I know I would need more info to
answer it. Maybe someone else can answer it with the current info, I can't.
If you provide answers to these questions, maybe someone can answer the
problem question.

http://www.knowdotnet.com

"Newbee" <an*******@disc ussions.microso ft.com> wrote in message
news:EA******** *************** ***********@mic rosoft.com...
Hola,

I wanted to kno how to clear the current text that is displayed in my combobox. I am filling it with a query which is run against my database.

I have tried this but it not work.

Combobox1.text = ""

am i using the wrong event?
Can someone advise me with correction?

Jul 21 '05 #2
Newbee:

What event are you firing this from? Is it a bound control or are you
populating it as you walk through a datareader for instance.

I just added a bound combobox control to a form, bound it to an array and
used this code:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

ComboBox1.Text = String.Empty

End Sub
Which worked fine. If I had done it on Form_Load, it wouldn't have b/c the
binding took place after I called this, perhaps that's the problem? In
addition, I set the SelectedIndex to -1 and that cleared it as well.
ComboBox1.Selec tedIndex = -1

Can you post the whole code snippet or tell me more about how it's populated
and where you are calling this from?

"Newbee" <an*******@disc ussions.microso ft.com> wrote in message
news:EA******** *************** ***********@mic rosoft.com...
Hola,

I wanted to kno how to clear the current text that is displayed in my combobox. I am filling it with a query which is run against my database.

I have tried this but it not work.

Combobox1.text = ""

am i using the wrong event?
Can someone advise me with correction?

Jul 21 '05 #3
I'd seriously recommend another approach....Fir st, pull over two queries
with two dataadapters. If the tables are in a Parent Child format, (where
the top combobox uses the parents data and the child data is displayed in
the bottom one, you may want to use a DataRelation). Or, if they aren't,
you can just bind the bottom one to a dataview and set it's rowfilter to
correspond to whatever was selected in the top combobox.

DataReaders rock and they are very easy to use..but you'll potentially be
making a LOT of trips to the DB that aren't necessary if you do it that way.

However, more to the point, what happens if you set the selectedIndex of the
combobox to -1? That should do it for you although I just used similar code
and can't cause the problem to happen.
If you want to pursue the DataBound method, this should help, and either
way, the -1 index should do it for you.
Here's some code I use to do essentailly the same thing with a grid. I bind
the grid to a dataview..Then when the comboboxes selectedindex changes, I
reset the rowfilter:
Dim dv2 As New DataView(ds.Tab les(0))

dv2.RowFilter = "Work_Type = '" CType(cboDepart ment.SelectedIt em, String)"'"

"Newbee" <an*******@disc ussions.microso ft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
I am filling the combobox like so:
Try
GioCn.Open()
Dim reader3 As SqlDataReader
reader3 = cmd.ExecuteRead er()
While reader3.Read
ComboBox1.Items .Add(reader3.Ge tSqlString(0))
End While
Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
GioCn.Close()
End Try

The above coding is fired when the combobox0 (the combobox above it) value is changed. (valuechanged). i.e when combobox0 value is changed, this code
is run to fill comboBox1. I write the combobox1.text = "" in a button onclick event. (like a reset button)
the code does not seem to clear the text value of my combobox!!! :(

Jul 21 '05 #4
I'm about to head home now...if you want, I can send you a working example
of this. Cheers,

Bill
"Newbee" <an*******@disc ussions.microso ft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
I am filling the combobox like so:
Try
GioCn.Open()
Dim reader3 As SqlDataReader
reader3 = cmd.ExecuteRead er()
While reader3.Read
ComboBox1.Items .Add(reader3.Ge tSqlString(0))
End While
Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
GioCn.Close()
End Try

The above coding is fired when the combobox0 (the combobox above it) value is changed. (valuechanged). i.e when combobox0 value is changed, this code
is run to fill comboBox1. I write the combobox1.text = "" in a button onclick event. (like a reset button)
the code does not seem to clear the text value of my combobox!!! :(

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7493
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the project, the combox box initially displays an empty selection. When I click on the drop down arrow I see the "Make a Selection" followed by the other choices. How can I move everything up so that the "Make a Selection" is the default value in...
0
291
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data item selected in Combobox 1. This is done through the .AddItem method of Combobox 2 looping through the recordset. This works fine, until --> the data item in the Combobox 1 is changed, then Combobox 2 just appends the "new" related child data...
0
2378
by: tupolev | last post by:
Hi, I already post this item but now I know whats wrong: I want to allow the user to edit the items in a combobox. The problem is that the textchange event works just one time (for the first changed letter) because he reset the selectedindex of the combobox to -1. In debug mode I can't see where he does this. How can I solve this? My code sofar: contactlijst is a structure and the volgnummer is the index of the item in the combobox
9
7321
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the combobox, but I can't find anything that will let me do that. - Don
4
437
by: Newbee | last post by:
Hola I wanted to kno how to clear the current text that is displayed in my combobox I am filling it with a query which is run against my database I have tried this but it not work Combobox1.text = " am i using the wrong event
2
5214
by: Brett Romero | last post by:
After I remove all items from a combobox, the last selected item remains in the display area. I've tried: mycbox.SelectedText = string.Empty; and mycbox.refresh(); How do I clear the display area of a combobox after removing all of its
1
1740
by: ray well | last post by:
i'm loading a combobox from a database in code, by setting the the DataSouce to a table, and the DisplayMember to a field. it loads the first row into the text area of the combobox automatically. i don't want that. i used to clear it up by setting ComboBox1.Text="", after loading it. but i had to put the combobox on a tab page of a tab control. ComboBox1.Text="" works only if the tab page has the focus when that code
7
3582
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR Me.cboLocation.Text = ""
5
18737
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either. Does anyone have some good code for an owner-drawn combobox?
0
8840
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.