Orann
Topic Author
Posts: 5
Joined: 12 Dec 2014, 02:50

Cannot get current text in an Editable ComboBox

05 Feb 2015, 06:43

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.
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: Cannot get current text in an Editable ComboBox

09 Feb 2015, 13:52

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; 
 
Luro
Posts: 3
Joined: 18 Feb 2015, 10:22

Re: Cannot get current text in an Editable ComboBox

18 Feb 2015, 10:47

I tried to convert the Tag to String in C++ like you did in your code but I get an error that the argument of Noesis::Core::BaseComponent* can not be converted into Noesis::Core::Boxing::BoxedValue*

My code looks like this:
	Noesis::Gui::Image* cbi = NsStaticCast<Noesis::Gui::Image*>(mCurrentDragImage);
	NsString& tag2 = Noesis::Core::Boxing::Unbox<NsString>(cbi->GetTag());
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: Cannot get current text in an Editable ComboBox

18 Feb 2015, 12:48

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()));  
 
Luro
Posts: 3
Joined: 18 Feb 2015, 10:22

Re: Cannot get current text in an Editable ComboBox

19 Feb 2015, 15:24

Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: Cannot get current text in an Editable ComboBox

19 May 2015, 19:23

We fixed this for the next release 1.2.4, ComboBox.Text will be updated each time you write in the editable textbox ;)

Who is online

Users browsing this forum: Ahrefs [Bot] and 10 guests