Duble Quote in ComboBox Item

J

John W

I have a combobox containing the following items...

1"
2"
3"

I need to select one of those items and make it the current selected value
in the combobox. No problem with any other values (not containing " but
doesn't seem to work when the item contains ".

If there isnt a " in the item the following works great...

ComboBox1.Text = "2";


However this does not work...

ComboBox1.Text = "1\"";


Any ideas?
 
M

mick

John W said:
I have a combobox containing the following items...

1"
2"
3"

I need to select one of those items and make it the current selected value
in the combobox. No problem with any other values (not containing " but
doesn't seem to work when the item contains ".

If there isnt a " in the item the following works great...

ComboBox1.Text = "2";


However this does not work...

ComboBox1.Text = "1\"";


Any ideas?


Shouldnt it be ComboBox.SelectedText = "1\"";

mick
 
P

Peter Duniho

(Off-topic newsgroups removed from follow-ups)
[...]
However this does not work...

ComboBox1.Text = "1\"";

Any ideas?


Shouldnt it be ComboBox.SelectedText = "1\"";

The SelectedText property relates specifically to the edit area.
Depending on the state of the control at time you use it, it may or may
not correlate to the specific _item_ selected in the control (if any).

That said…

To the OP: ComboBox does override the Text property, and should select
the appropriate item when you set it. Are you _sure_ that your ComboBox
items have _exactly_ the same text you're setting? And not, for
example, a ” double-quote in the ComboBox while your code has a "
double-quote (i.e. a right-side double-quote, as opposed to a plain
either-side double-quote)?

The Text property works fine for me as advertised. If it's not a string
mis-match problem, you need to post a concise-but-complete code example
that reliably demonstrates the problem. I'm unable to reproduce the
problem you describe with just the information you've provided so far.

Pete
 
F

Family Tree Mike

It works for me. Oddly though, if you use it just after
InitializeComponants() it doesnt.

mick

I believe you want to be using comboBox1.SelectedItem = "2\"". This
works for me in VS 2010 RC 1 in just after the InitializeComponents, by
the way.
 
M

mick

Family Tree Mike said:
I believe you want to be using comboBox1.SelectedItem = "2\"". This works
for me in VS 2010 RC 1 in just after the InitializeComponents, by the way.

I thought I`d tried SelectedItem but I cant have. You are right that does
work.

mick
 
J

John W

Still doesn’t work. Nothing seems to work. How do I select and item that
has a " in it?


Peter Duniho said:
(Off-topic newsgroups removed from follow-ups)
[...]
However this does not work...

ComboBox1.Text = "1\"";

Any ideas?


Shouldnt it be ComboBox.SelectedText = "1\"";

The SelectedText property relates specifically to the edit area. Depending
on the state of the control at time you use it, it may or may not
correlate to the specific _item_ selected in the control (if any).

That said…

To the OP: ComboBox does override the Text property, and should select the
appropriate item when you set it. Are you _sure_ that your ComboBox items
have _exactly_ the same text you're setting? And not, for example, a ”
double-quote in the ComboBox while your code has a " double-quote (i.e. a
right-side double-quote, as opposed to a plain either-side double-quote)?

The Text property works fine for me as advertised. If it's not a string
mis-match problem, you need to post a concise-but-complete code example
that reliably demonstrates the problem. I'm unable to reproduce the
problem you describe with just the information you've provided so far.

Pete
 
M

mick

John W said:
Still doesn’t work. Nothing seems to work. How do I select and item that
has a " in it?

It`s funny, when I first tried it with comboBox1.Text I couldnt get it to
work either (must have been a typo.

Cut and Paste the line below (just in case you have a typo also).
comboBox1.Text = "1\"";

It definately works.

mick
 
P

Peter Duniho

John said:
Still doesn’t work. Nothing seems to work. How do I select and item
that has a " in it?

I already explained: you select it the same way you select any other
item with any given text.

What you claim doesn't work does work fine, assuming no bugs. So, you
obviously have a bug in your code.

But if you don't post your code – specifically, a concise-but-complete
code example that reliably reproduces the problem – no one can explain
to you what bug you have.

If you are really that against providing a proper code example, the only
other thing that might be worth considering is what .NET version you
have installed. There's a very teeny tiny possibility that you've come
across something that works in the current version, but not an earlier
version.

But my money's on a bug in your code.

Pete
 
F

Family Tree Mike

Still doesn’t work. Nothing seems to work. How do I select and item
that has a " in it?


Peter Duniho said:
(Off-topic newsgroups removed from follow-ups)
[...]
However this does not work...

ComboBox1.Text = "1\"";

Any ideas?


Shouldnt it be ComboBox.SelectedText = "1\"";

The SelectedText property relates specifically to the edit area.
Depending on the state of the control at time you use it, it may or
may not correlate to the specific _item_ selected in the control (if
any).

That said…

To the OP: ComboBox does override the Text property, and should select
the appropriate item when you set it. Are you _sure_ that your
ComboBox items have _exactly_ the same text you're setting? And not,
for example, a ” double-quote in the ComboBox while your code has a "
double-quote (i.e. a right-side double-quote, as opposed to a plain
either-side double-quote)?

The Text property works fine for me as advertised. If it's not a
string mis-match problem, you need to post a concise-but-complete code
example that reliably demonstrates the problem. I'm unable to
reproduce the problem you describe with just the information you've
provided so far.

Pete

Again (I posted this earlier), to select an item, you should be using
comboBox1.SelectedItem = "2\"".

If that doesn't work, but comboBox1.SelectedIndex = 1 does work, then
your items are not matching the choices.
 
J

John W

Very strange behavior. When my items contain a blank line as the first item
in the list of items the .text = "2\""; does not work. As soon as I remove
the blank line from the list it works fine.
 
P

Pasan Indeewara

John W said:
Still doesn't work...

Cannot simulate this issue, I would suggest you to create a simple form in
VS, then add a combobox and check you get the same issue, if not compare
it's properties with the one in the your app.

Still no luck, then Need more information like dotnet framework, OS info,
Application source (if possible), etc.
 

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