ComboBox Blank Entry

G

Guest

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
 
M

Mark Rae

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...
 
O

Otis Mukinfus

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
 
G

Guest

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 said:
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
 
O

Otis Mukinfus

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 said:
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
 
G

Guest

I'll try it thank you Otis

--Steve

Otis Mukinfus said:
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 said:
On Sat, 11 Feb 2006 14:32:31 -0800, "Steve B."

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top