Page 1 of 1

Cannot get current text in an Editable ComboBox

Posted: 05 Feb 2015, 06:43
by Orann
Hey all,

I'm creating an editable combobox with a few pre-set options, designed to let a user type in a destination for a file or select from some convenient presets, but I've run into a few problems. I'm creating the combobox like this:
        <ComboBox VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="6, 0" Height="24" 
                      IsEditable="True" IsSynchronizedWithCurrentItem="True" Name="fileLocationBox" SelectedIndex="0">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                
                <ComboBoxItem Tag="MyDocuments">MyDocuments/PEVS</ComboBoxItem>
                <ComboBoxItem Tag="Desktop">Desktop</ComboBoxItem>
                <ComboBoxItem Tag="MyPictures">MyPictures/PEVS</ComboBoxItem>
                <ComboBoxItem >Current Folder</ComboBoxItem>
            </ComboBox>
It seems to be that comboBox.GetText() should return the current state of the text in the box that's being edited, but unfortunately it doesn't seem to. Instead, i'm getting what was originally in that spot before any editing took place (I.E: It's impossible for me to find out what the current string of edited text in the combobox is).

In Addition to this, when I call comboBox.GetSelectedItem().GetTag() It gives me a BaseComponent object back, which doesn't contain any information - notably it doesn't contain the string tag that I originally put there, meaning that too is impossible to get out. I can work around this issue by pushing to information into the name field (which is correctly preserved), but being unable to get the current text in the editable text box of the combobox seems to make ComboBox.IsEditable useless.

Re: Cannot get current text in an Editable ComboBox

Posted: 09 Feb 2015, 13:52
by sfernandez
You are right, our implementation does the opposite thing (set TextBox text from the selected item text only) as expected (update ComboBox.Text with anything typed in the editable TextBox) :(
We will fix it for the next release.

About the Tag property, which API are you using? Native C++ SDK or Unity C#?
If you have something like this:
<ComboBox>
  <ComboBoxItem Content="Item 1" Tag="Something 1"/>
  <ComboBoxItem Content="Item 2" Tag="Something 2"/>
  <ComboBoxItem Content="Item 3" Tag="Something 3"/>
</ComboBox>
In native c++ you can get the string stored in Tag as follows:

API 1.1
ComboBoxItem* cbi = NsStaticCast<ComboBoxItem*>(comboBox->GetSelectedItem());
NsString& tag = Boxing::Unbox<NsString>(NsStaticCast<Boxing::BoxedValue*>(cbi->GetTag()));
API 1.2
ComboBoxItem* cbi = NsStaticCast<ComboBoxItem*>(comboBox->GetSelectedItem());
const NsString& tag = Boxing::Unbox<NsString>(cbi->GetTag());
And in Unity:

API 1.1
ComboBoxItem cbi = comboBox.GetSelectedItem().As<ComboBoxItem>();
string tag = cbi.GetTag().AsString(); 
API 1.2
ComboBoxItem cbi = (ComboBoxItem)comboBox.SelectedItem;
string tag = (string)cbi.Tag; 

Re: Cannot get current text in an Editable ComboBox

Posted: 18 Feb 2015, 10:47
by Luro
-

Re: Cannot get current text in an Editable ComboBox

Posted: 18 Feb 2015, 12:48
by sfernandez
Sorry, it was my fault, the C++ code I posted is for 1.2 version too (I will edit the post to fix it).
For 1.1 version you have to cast to the expected argument type:
ComboBoxItem* cbi = NsStaticCast<ComboBoxItem*>(comboBox->GetSelectedItem());
NsString& tag = Boxing::Unbox<NsString>(NsStaticCast<Boxing::BoxedValue*>(cbi->GetTag()));  

Re: Cannot get current text in an Editable ComboBox

Posted: 19 Feb 2015, 15:24
by Luro
-

Re: Cannot get current text in an Editable ComboBox

Posted: 19 May 2015, 19:23
by sfernandez
We fixed this for the next release 1.2.4, ComboBox.Text will be updated each time you write in the editable textbox ;)