473,748 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I add a blank item to a combobox that is databound to a dataset?

I fill a table in a dataset with values that will be used by a combobox
for the combobox's items. The combobox is a drop down list that only
allows the user to select from the list but not enter any new values.
What I need to do is include a blank row in the list so that when it is
selected, the SelectedValue property returns a Null. I don't want to
add a record in the database with some field set to null because this
would have to be repeated for several languages since the values in the
list are language dependent. How can I add a blank item since the
combobox is bound to the dataset?

Thanks for your insight.
Johann Blake

Nov 17 '05 #1
6 8009
"Johann Blake" <jo*********@ya hoo.com> schrieb im Newsbeitrag
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I fill a table in a dataset with values that will be used by a combobox
for the combobox's items. The combobox is a drop down list that only
allows the user to select from the list but not enter any new values.
What I need to do is include a blank row in the list so that when it is
selected, the SelectedValue property returns a Null. I don't want to
add a record in the database with some field set to null because this
would have to be repeated for several languages since the values in the
list are language dependent. How can I add a blank item since the
combobox is bound to the dataset?

Thanks for your insight.
Johann Blake

You can add an additional row to the DataSet after filling it from the
database.

hth
Christof
Nov 17 '05 #2
The problem with that solution is that when the user selects a
different language (with a separate combobox), the list for the
combobox that is suppose to include a blank line will not include the
blank line. This is because this combobox is bound to a table whose
RowFilter is set to the language the user chooses. This would mean
having to add a blank row for each language selected. Any other ideas?

Johann

Nov 17 '05 #3
If you want to continue to use the DataView as your data source, then no,
there is not going to be a more elegant solution. You can either databind
the combo or manually populate the combo, not both. By using databinding to
populate the combo, you are ensuring that the combo cannot get it's data any
other way. Since you are using a DataView as the data source, the data
*must* be in the underlying table. So your options are fairly limited:

1) Manually populate the combo each time a user selects a different
language, which would allow you to add a blank row in code. You could
iterate through the rows in the DataView after adding the blank row.
2) Continue to bind the combo to the DataView, and add a blank row to the
underlying DataTable for each language.

If you just want to ensure that no item is selected when the combo is
populated, you can just set the SelectedIndex property to -1. However, I am
guessing you need the blank row to allow the user to "clear" the selection,
so setting the SelectedIndex probably won't help.

How are you using the blank row? If it is just to ensure that nothing is
selected when
"Johann Blake" <jo*********@ya hoo.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
The problem with that solution is that when the user selects a
different language (with a separate combobox), the list for the
combobox that is suppose to include a blank line will not include the
blank line. This is because this combobox is bound to a table whose
RowFilter is set to the language the user chooses. This would mean
having to add a blank row for each language selected. Any other ideas?

Johann

Nov 17 '05 #4
"Johann Blake" <jo*********@ya hoo.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
How can I add a blank item since the combobox is bound to the dataset?

After the data is bound, can't you just run

<comboBox>.Item s.Insert(0, "");
Nov 17 '05 #5
Did you try this yourself? I think you will find it does not work (it
definitely does not work on any of the machines to which I have access). You
will get the following error:

"An unhandled exception of type 'System.Argumen tException' occurred in
system.windows. forms.dll
Additional information: Cannot modify the Items collection when the
DataSource property is set."

And if you try to Insert (or Add) to the item collection before setting the
data source, your work is undone once the data source is set.

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:e0******** ******@TK2MSFTN GP14.phx.gbl...
"Johann Blake" <jo*********@ya hoo.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
How can I add a blank item since the combobox is bound to the dataset?

After the data is bound, can't you just run

<comboBox>.Item s.Insert(0, "");

Nov 17 '05 #6
I decided to add a single row to the DataView and leave its TextID set
to null. However, to avoid adding an additional record for each
language, I simply set the RowFilter to include the null record:

myDataView.RowF ilter = "LanguageID = " + id + " Or (TextID is null)";

Johann

Nov 17 '05 #7

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

Similar topics

2
3450
by: Phil | last post by:
My form uses a dataset containing two tables, a base table (Contact) and a lookup table (Insurer). My combobox is bound as follows: DataSource = datasetContact DisplayMember = Insurer.InsurerName ValueMember = Insurer.InsurerId DataBindings.SelectedValue = Contact.InsurerId It generally works fine. I am able to navigate records and
3
2124
by: Support | last post by:
Hi All, I am working in VB.NET. I have a data bound control (combobox) which I want to fill with a certain field of my table from database ( SQL as backend). The issue is, I want these values to fill the combo at the index specified by me, ie, not the usual 0,1,2.... by default. Also, not dataset, but I am using dataReader. Can anyone send me the sample code for the same? Thanks for your help.
11
2594
by: Bill nguyen | last post by:
Table A has 2 columns: recID int recName String I need to load all recName into combobox B using B.Items.Add(recName). This is no problem. However, I would like to be able to match ComboxBox B's index with table A's recID so that I can use B.SelectedIndex to update any table that uses Table A's recID. Currently, I have to use a clumsy routine to find recID from B.text
7
4565
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table (called "Data") with two columns "Id" and "Description". Id contains a code and description contains the description that is displayed in the combobox.
6
4913
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox are not data bound (they just use the built in collection property of the ComboBox), and they are all set to use the DropDownList style. When moving from record to record via a BindingNavigator or a DataGridView (in master/detail format), the text...
9
4461
by: Kay | last post by:
Hi all, Could you tell me the best way to add a blank item(as first item) in a data binded combo box? Because I think I didn't do it right and it generate an error if the second item(after the top blank item) is selected by using Combo.SelectedValue : "Specified argument was out of the range of valid values. Parameter name: '-2147483648' is not a valid value for 'index'.
5
25031
by: Steve B. | last post by:
Without adding whitespace to the ComboBox datasource is there a way I can add a blank entry or, a reset entry, to the ComboBox dropdown Thanks Steve
3
4696
by: Benny | last post by:
Does anyone know how I would go about adding a blank value to the list of items in a ComboBox that has a set datasource? Thank in advance!
4
6666
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a common/standard .NET control accepting an Object as a parameter type? In Web Forms, there is a ListItem object that can be passed in to add/retrieve objects from a DropDownItems collection. I searched Google groups, and all the solutions I'm finding...
0
8995
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
8832
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
9558
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...
1
9331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9253
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6798
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
6077
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
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

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.