472,146 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

ComboBox Blank Entry

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
5 24803
"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
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
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
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
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.

Similar topics

3 posts views Thread by Craig G | last post: by
3 posts views Thread by JD Williams | last post: by
4 posts views Thread by Jerad Rose | last post: by

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.