By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

ComboBox Blank Entry

P: n/a
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
Feb 11 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Steve B." <St****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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


Not sure what you mean by whitespace - if you add a blank entry to a
ComboBox, that's exactly what it will be - a blank entry...
Feb 12 '06 #2

P: n/a
On Sat, 11 Feb 2006 14:32:31 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:
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

If you mean you want to add a value to index zero of the combo box,
the way to do that is to populate the combo from the data source and
then add it by doing this:

private void FillButton_Click(object sender, EventArgs e)
{
string[] items = { "One", "Two", "Three" };

TestComboBox.Items.AddRange(items);
TestComboBox.Items.Insert(0, "Top Item");
TestComboBox.SelectedIndex = 0;
}
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Feb 12 '06 #3

P: n/a
Thanks Mark/Otis for replying

My datasource is a database table.

Lets say the datasource for the CB dropdown is a database table of colors.
If the user selects the color "Red" in the dropdown and then changes his mind
later and decides not to select a any kind of color his only choice is to
backspace to remove his previous "Red" selection. I wanted to give the user
a choice to select a blank entry in the dropdown menu. I didn't want to add
a blank row to the database (bad practice).

Mark, I'm going to do some tests regarding your code

Thanks
Steve

"Otis Mukinfus" wrote:
On Sat, 11 Feb 2006 14:32:31 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:
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

If you mean you want to add a value to index zero of the combo box,
the way to do that is to populate the combo from the data source and
then add it by doing this:

private void FillButton_Click(object sender, EventArgs e)
{
string[] items = { "One", "Two", "Three" };

TestComboBox.Items.AddRange(items);
TestComboBox.Items.Insert(0, "Top Item");
TestComboBox.SelectedIndex = 0;
}
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Feb 12 '06 #4

P: n/a
On Sun, 12 Feb 2006 11:56:03 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:
Thanks Mark/Otis for replying

My datasource is a database table.

Lets say the datasource for the CB dropdown is a database table of colors.
If the user selects the color "Red" in the dropdown and then changes his mind
later and decides not to select a any kind of color his only choice is to
backspace to remove his previous "Red" selection. I wanted to give the user
a choice to select a blank entry in the dropdown menu. I didn't want to add
a blank row to the database (bad practice).

Mark, I'm going to do some tests regarding your code

Thanks
Steve

"Otis Mukinfus" wrote:
On Sat, 11 Feb 2006 14:32:31 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:
>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

If you mean you want to add a value to index zero of the combo box,
the way to do that is to populate the combo from the data source and
then add it by doing this:

private void FillButton_Click(object sender, EventArgs e)
{
string[] items = { "One", "Two", "Three" };

TestComboBox.Items.AddRange(items);
TestComboBox.Items.Insert(0, "Top Item");
TestComboBox.SelectedIndex = 0;
}
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Change "Top Item" to "" and you will get a blank entry in the first
row. Then when the user selects an item from the ComboBox you can do
the appropriate thing based on the selected index.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Feb 12 '06 #5

P: n/a
I'll try it thank you Otis

--Steve

"Otis Mukinfus" wrote:
On Sun, 12 Feb 2006 11:56:03 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:
Thanks Mark/Otis for replying

My datasource is a database table.

Lets say the datasource for the CB dropdown is a database table of colors.
If the user selects the color "Red" in the dropdown and then changes his mind
later and decides not to select a any kind of color his only choice is to
backspace to remove his previous "Red" selection. I wanted to give the user
a choice to select a blank entry in the dropdown menu. I didn't want to add
a blank row to the database (bad practice).

Mark, I'm going to do some tests regarding your code

Thanks
Steve

"Otis Mukinfus" wrote:
On Sat, 11 Feb 2006 14:32:31 -0800, "Steve B."
<St****@discussions.microsoft.com> wrote:

>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
If you mean you want to add a value to index zero of the combo box,
the way to do that is to populate the combo from the data source and
then add it by doing this:

private void FillButton_Click(object sender, EventArgs e)
{
string[] items = { "One", "Two", "Three" };

TestComboBox.Items.AddRange(items);
TestComboBox.Items.Insert(0, "Top Item");
TestComboBox.SelectedIndex = 0;
}
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Change "Top Item" to "" and you will get a blank entry in the first
row. Then when the user selects an item from the ComboBox you can do
the appropriate thing based on the selected index.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Feb 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.