[SOLVED] Setting ComboBox.SelectedValue error

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
sebas
Posts: 21
Joined: Fri Oct 27, 2017 7:03 am

[SOLVED] Setting ComboBox.SelectedValue error

Postby sebas » Tue Oct 31, 2017 10:53 pm

Code: Select all

<ComboBox x:Name="ComboBox1" />


Code: Select all

 public partial class MainPage : Page
    {
        public class myType
        {
            public Int32 Id { get; set; }
            public String Name { get; set; }
        }
        public MainPage()
        {
            this.InitializeComponent();

            var c = new ObservableCollection<myType>() { new myType() { Id = 1, Name = "11" }, new myType() { Id = 2, Name = "22" } };
            ComboBox1.SelectedValuePath = "Id";
            ComboBox1.DisplayMemberPath = "Name";
            ComboBox1.ItemsSource = c;
            ComboBox1.SelectedValue = 2; // item where id = 2 Error here!
        }
    }


at last string ComboBox1.SelectedValue = 2 i got error. Is it bug?

System.InvalidOperationException occurred
HResult=0x80131509
Message=Sequence contains no matching element
Source=System.Core
StackTrace:
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at Windows.UI.Xaml.Controls.Primitives.Selector.SelectedValue_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
at DotNetForHtml5.Core.INTERNAL_PropertyStore.OnPropertyChanged(INTERNAL_PropertyStorage storage, Object oldValue, Object newValue, PropertyMetadata typeMetadata)
at DotNetForHtml5.Core.INTERNAL_PropertyStore.RaisePropertyChangedAndCascadeToChildren(INTERNAL_PropertyStorage storage, Object oldValue, Object newValue, PropertyMetadata typeMetadata)
at DotNetForHtml5.Core.INTERNAL_PropertyStore.SetSpecificValue(INTERNAL_PropertyStorage storage, KindOfValue kindOfValueToSet, Object newValue, PropertyMetadata typeMetadata)
at DotNetForHtml5.Core.INTERNAL_PropertyStore.SetLocalValue(INTERNAL_PropertyStorage storage, Object newValue)
at Windows.UI.Xaml.DependencyObject.SetLocalValue(DependencyProperty dependencyProperty, Object value)
at Windows.UI.Xaml.DependencyObject.SetValueInternal(DependencyProperty dependencyProperty, Object value)
at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dependencyProperty, Object value)
at Windows.UI.Xaml.Controls.Primitives.Selector.set_SelectedValue(Object value)
at Application1.MainPage..ctor() in C:\Users\user1\source\repos\Application1\Application1\MainPage.xaml.cs:line 26
at Application1.App..ctor() in C:\Users\user1\source\repos\Application1\Application1\App.xaml.cs:line 18

JS-Support @Userware
Site Admin
Posts: 912
Joined: Tue Apr 08, 2014 3:42 pm

Re: Setting ComboBox.SelectedValue error

Postby JS-Support @Userware » Thu Nov 02, 2017 1:04 am

Hi,

Thanks for reporting this issue. We are going to investigate and fix it asap.

In the meantime, you can try putting that line of code in the Loaded event instead:

Code: Select all

public MainPage()
        {
            this.InitializeComponent();

            var c = new ObservableCollection<myType>() { new myType() { Id = 1, Name = "11" }, new myType() { Id = 2, Name = "22" } };
            ComboBox1.SelectedValuePath = "Id";
            ComboBox1.DisplayMemberPath = "Name";
            ComboBox1.ItemsSource = c;
            this.Loaded += (s,e) => {
                  ComboBox1.SelectedValue = 2; // item where id = 2 Error here!
               };
        }


You can also try using the non-native ComboBox:

Code: Select all

<ComboBox UseNativeComboBox="False"/>


Thanks
Regards,
JS-Support

JS-Support @Userware
Site Admin
Posts: 912
Joined: Tue Apr 08, 2014 3:42 pm

Re: Setting ComboBox.SelectedValue error

Postby JS-Support @Userware » Tue Nov 14, 2017 4:39 am

Hi,

We have fixed the issue in Beta 12.6, which will be released in a few days.

Thanks.
Regards,
JS-Support


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests