Re: ComboBox.SelectedText always returning empty string by Tim
Tim
Tue Jul 13 16:18:28 CDT 2004
The "SelectedText" property returns the selected text in the editable
portion of the control. And if DropDownStyle is set to
ComboBoxStyle.DropDownList it will return, as the expected behavior, an
empty string. The whole purpose of this property is so that when the user
selects all, or a portion, of the text in the "edit" portion of ComboBox you
can programmatically determine what that selection is. I suspect that when
you are trying to see the"SelectedText" when the DropDownStyle is set to the
ComboBoxStyle.DropDown you are causing the focus to be taken away from the
ComboBox, and thus the "SelectedText" value is empty - nothing selected. In
this situation try using the "SelectedItem" property instead.
if (this.comboBox1.SelectedItem is string)
{
MessageBox.Show((string)this.comboBox1.SelectedItem);
}
--
Tim Wilson
.Net Compact Framework MVP
"Dano" <dtemple7502@rogers.com> wrote in message
news:nWXIc.683$hs7.622@news04.bloor.is.net.cable.rogers.com...
> Yes ... doublechecked. It is set to DropDownList. In fact it doesn't
seem
> to matter what it is set to, it always returns an empty string.
>
> Dano
>
> "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
> news:uGf5piRaEHA.1508@TK2MSFTNGP09.phx.gbl...
> > I assume that the DropDownStyle is set to "DropDownList". From the help:
> > "If DropDownStyle is set to ComboBoxStyle.DropDownList, the return is an
> > empty string ("")."
> >
> > --
> > Tim Wilson
> > .Net Compact Framework MVP
> >
> > "Dano" <dtemple7502@rogers.com> wrote in message
> > news:4uXIc.442$hs7.343@news04.bloor.is.net.cable.rogers.com...
> > > Hi all,
> > >
> > > I know I must be missing something very simple here, but this little
> > problem
> > > is baffling me.
> > >
> > > If you have a combobox called cmbMyCombo and add a bunch of strings to
> it,
> > > say, "Apple", "Pear" and "Orange", and then call the
> > > cmbMyCombo.SelectedIndex it will tell you the index of the item that
was
> > > selected. However, you would think that if you called
> > > cmbMyCombo.SelectedText it would give you the TEXT of whatever was
> > selected
> > > (i.e. Apple, Pear etc), but all it does is return an empty string.
Does
> > > anyone know why this is?
> > >
> > > Dano
> > >
> > >
> >
> >
>
>