473,419 Members | 4,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Stupid Question!!

I am having a heck of a time trying to refresh data in a combobox. I have a
combo box that periodically needs to have its bound data refreshed. I can
refresh the data, but every time I refresh it the updated contents of my
data source is added to the combo and the existing list is not cleared.

I have tried calling Items.Clear() before the bind and this didn't work. It
told me I couldn't call it when .DataSource was set, so I set it to Nothing
and then called Items.Clear(). Still nothing.

I know that I am probably missing something blatantly obvious! Does anybody
have any suggestions?

Thank You

Brian
Nov 23 '05 #1
9 985
Brian,

Can you show us some code (including the method declaration) where you do
this?

Cor
Nov 23 '05 #2
The following lines should clear it:

myCombo.DataSource = Nothing
myCombo.ValueMember = String.Empty
myCombo.DisplayMember = String.Empty
After that just rebind it again. If this doesn't work
you'll need to show your code.

/claes

"Brian" <br***********@nospam.gmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am having a heck of a time trying to refresh data in a combobox. I have a combo box that periodically needs to have its bound data refreshed. I can
refresh the data, but every time I refresh it the updated contents of my
data source is added to the combo and the existing list is not cleared.

I have tried calling Items.Clear() before the bind and this didn't work. It told me I couldn't call it when .DataSource was set, so I set it to Nothing and then called Items.Clear(). Still nothing.

I know that I am probably missing something blatantly obvious! Does anybody have any suggestions?

Thank You

Brian

Nov 23 '05 #3
Thank you for the replies!

As it turns out, I don't think it is my combo causing the problem. I think
it is my dataset.

Here is the scenario. I have a form with a combo on it. Beside the combo is
a button that displays a dialog that will add a record to the table that my
combo is bound to. On closing the dialog I Insert the new record into the
database using an Insert statement and .ExecuteNonQuery().

When the dialog is close, I refresh my dataset and rebind the combo. When I
refresh the dataset, the database table contents is appended to the end of
the dataset table. The second set of data does contain the new record.

Here is an example:

myCnn.Open()
cmd = new SQLCommand("Select * from tblUOM Order By fldName")
adapt = new SQLDataAdapter(cmd, myCnn)
adapt.fill(myDataSet, "tblUOM")
myCnn.Close()

MsgBox(myDataSet.Tables("tblUOM").Rows.Count.toStr ing())

The actual code I was working on is at home, so that is off the top of my
head. It is pretty straight forward, nothing out of the ordinary. When it
runs through the first time, My message box displays 4, but the second time
it displays 9.
The contents of my combo go from {1,2,3,4} to {1,2,3,4,1,2,3,4,5}. I have
done this same thing in ASP.Net using C#, and the dataset updates like I
would expect. This time I am using VBExpress and SQLExpress. Is that were
the bug lies or is it something I am doing?

Shouldn't the dataset just update on the second fill or do I have to clear
the table in the dataset and refill it (which does work by the way)?

Anyway, being a bit long winded and probably rambling at this point.

Thanks

Brian
"Brian" <br***********@nospam.gmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am having a heck of a time trying to refresh data in a combobox. I have a
combo box that periodically needs to have its bound data refreshed. I can
refresh the data, but every time I refresh it the updated contents of my
data source is added to the combo and the existing list is not cleared.

I have tried calling Items.Clear() before the bind and this didn't work.
It
told me I couldn't call it when .DataSource was set, so I set it to
Nothing
and then called Items.Clear(). Still nothing.

I know that I am probably missing something blatantly obvious! Does
anybody
have any suggestions?

Thank You

Brian

Nov 23 '05 #4
Brian,

What we don't see is how you bind that dataset to the combobox.

Normal this will be

myCombo.DataSource = myDataset.Tables("tblUOM")
myCombo.ValueMember = "TheValueColumn"
myCombo.DisplayMember = "TheDisplayColumn"

Do you do it like this, and than where

Cor
Nov 23 '05 #5
I am binding the combo box right after the msgbox in my last example and
doing so exactly as you showed.

I have refocused my attention on the dataset however. The msgbox is telling
my I have 9 rows and not 4, my combobox is displaying the bound source
correctly.

Not sure why it isn't refreshing the dataset properly

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Brian,

What we don't see is how you bind that dataset to the combobox.

Normal this will be

myCombo.DataSource = myDataset.Tables("tblUOM")
myCombo.ValueMember = "TheValueColumn"
myCombo.DisplayMember = "TheDisplayColumn"

Do you do it like this, and than where

Cor

Nov 23 '05 #6
Brian,

How many times do you do that fill?

Cor
Nov 23 '05 #7
Once when the form loads and then again when the database changes. (Which is
triggered by user action on the form, popping up a dialog to add a new Unit
type. Which may or may not happen at all)

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Brian,

How many times do you do that fill?

Cor

Nov 23 '05 #8
Brian,

Can you try what happens clear the dataset before that fill than.

ds.clear

Cor
Nov 23 '05 #9
Cor,

I have done a ds.tables["tblUOM"].Clear() and it works.
Maybe this is the route that I have to go, even thought it is supposed to
work the other way too!

Thanks,

Brian
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Brian,

Can you try what happens clear the dataset before that fill than.

ds.clear

Cor

Nov 23 '05 #10

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

Similar topics

2
by: Strange Cat | last post by:
Hi everyone! I have this stupid question: How can I convert a string into all CAPITALS letters in the VS.NET IDE??? Is there a keyboard shortcut to accomplish this? Thanx in advance ASC
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
4
by: IS | last post by:
At the recommendation of several people in this newsgroup I have downloaded two or three Compilers. One is the Beta version of Microsoft's Visual C++ 2005. I have entered a complete beginner code...
1
by: Amar | last post by:
I have a created 2 single signon projects that works fine, by using IIdentity, my stupid question is that how do i clear the User object. After the user navigates through the sites by clicking...
6
by: Bart Schelkens | last post by:
Hi, I have kind of a stupid question (at least to me). Somebody asked me what the difference was between asp.net and vb.net. Since I create my webapplications with vb.net I couldn't think of a...
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
4
by: K8CPA | last post by:
Hi Guys, I've got a question from a stupid question from a clueless computer operator's standpoint. I use Windows XP. SP2, and I've got all these neat little programs. What language do they...
2
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to...
9
by: AWW | last post by:
Running XP - Visual Studio 2005 - VB Want to have duplicate projects - one safe and stable - other for experimenting Can't fine easy way to make duplicate project. Stupid question? or stupid ME?...
9
by: Alec | last post by:
Sorry guys, stupid question.... Am no programming expert and have only just started using php for creating dynamic news pages. Then I see a dynamic website without the php extension. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.