473,326 Members | 2,048 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,326 software developers and data experts.

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 7975
"Johann Blake" <jo*********@yahoo.com> schrieb im Newsbeitrag
news:11**********************@g43g2000cwa.googlegr oups.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*********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.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*********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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>.Items.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.ArgumentException' 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**************@TK2MSFTNGP14.phx.gbl...
"Johann Blake" <jo*********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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>.Items.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.RowFilter = "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
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 =...
3
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...
11
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...
7
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...
6
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...
9
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...
5
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
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
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.