locked
How to Get Selected Item In Windows:UI::Xaml::Controls::ComboBox (WinRT)

    Question

  • I have added item in the ComboBox.I am not able to retrieve the selected item if I Select some Item in the combobox.

    Most of the combox Propertise return Object Type and if If I try to do ToString() on the object it return Weird Value. 

    I tried these Propertise.

    MainPage::cmbDeviceList_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e){

    auto str = cmbDeviceList->SelectedItem->ToString;

    auto str1 = cmbDeviceList->SelectedValue->ToString();

    }

    My Query is 

    1. How to Retrieve the items from the combobox On user selection

    2. Why Most of the properties return Object.Is the purpose of keeping Object is to allow developer to insert class struct? 

     

    Friday, November 11, 2011 5:53 AM

Answers

  • ToString on an Object^ reference will always invoke Object::ToString (quite different to .NET ToString behavior). You won't be able to override ToString in your derived classes.

     

    What you probably need to do is to cast the returned Object^ to your DerivedType^ that you added to the ListBox or ComboBox.


    http://blog.voidnish.com
    • Marked as answer by chris_vr Saturday, November 12, 2011 5:43 PM
    Friday, November 11, 2011 12:52 PM

All replies

  • ToString on an Object^ reference will always invoke Object::ToString (quite different to .NET ToString behavior). You won't be able to override ToString in your derived classes.

     

    What you probably need to do is to cast the returned Object^ to your DerivedType^ that you added to the ListBox or ComboBox.


    http://blog.voidnish.com
    • Marked as answer by chris_vr Saturday, November 12, 2011 5:43 PM
    Friday, November 11, 2011 12:52 PM
  • I have added string in combobox .Do you mean I need the Object^ to String^???
    Friday, November 11, 2011 6:04 PM
  • I have added string in combobox .Do you mean I need the Object^ to String^???

    Yes. Have you tried that yet?
    http://blog.voidnish.com
    Friday, November 11, 2011 7:05 PM
  • Yup Its Working...

    Thanks Nishant!

    Saturday, November 12, 2011 5:43 PM