We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Set SelectedItem by Code (MVVM)

Thread ID:

Created:

Updated:

Platform:

Replies:

121338 Dec 2,2015 03:03 PM Feb 16,2016 06:17 AM WPF 3
loading
Tags: SfMultiColumnDropDownControl
Feneberg
Asked On December 2, 2015 03:03 PM

How can i set the SelectedItem by Code in the ViewModel?

Have you any idea..

If i set the SelectedItem i got an error:

 <syncfusion:SfMultiColumnDropDownControl Grid.Row="1" Grid.Column="1" Height="22" Margin="5,4,0,5"  x:Name="MultiColumnControl"
                                                         VerticalAlignment="Center"
                                                         AllowAutoComplete="True"
                                                         AllowCaseSensitiveFiltering="False"
                                                         AllowImmediatePopup="True"
                                                         AllowIncrementalFiltering="True"
                                                         AutoGenerateColumns="False"
                                                         DisplayMember="CompanyName"
                                                         ItemsSource="{Binding AllCompanies}"
                                                         PopupWidth="400"
                                                         ReadOnly="False"
                                                         SelectedItem="{Binding SelectedCompany, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                         ValueMember="CompanyName">
            <syncfusion:SfMultiColumnDropDownControl.Columns>
                <syncfusion:GridTextColumn HeaderText="Id" MappingName="Id" IsHidden="True"/>
                <syncfusion:GridTextColumn Width="70" HeaderText="Uid"
                                                      MappingName="UidNumber"
                                                      TextAlignment="Center"
                                                      DisplayBinding="{Binding UidNumber}" />
                <syncfusion:GridTextColumn Width="120" HeaderText="Firma"
                                                      MappingName="CompanyName"
                                                      TextAlignment="Center"
                                                      DisplayBinding="{Binding CompanyName}" />
                <syncfusion:GridTextColumn Width="120" HeaderText="Straße"
                                                      MappingName="Street"
                                                      TextAlignment="Center"
                                                      DisplayBinding= "{Binding Street}" />
                <syncfusion:GridTextColumn Width="70" HeaderText="Postleitzahl"
                                                      MappingName="PostalCode"
                                                      TextAlignment="Center"
                                                      DisplayBinding= "{Binding PostalCode}"/>
                <syncfusion:GridTextColumn Width="100" HeaderText="Stadt"
                                                      MappingName="City"
                                                      TextAlignment="Center"
                                                      DisplayBinding= "{Binding City}"/>
                <syncfusion:GridTextColumn Width="100" HeaderText="Land"
                                                      MappingName="Country"
                                                      TextAlignment="Center"
                                                      DisplayBinding= "{Binding Country}"/>
            </syncfusion:SfMultiColumnDropDownControl.Columns>
        </syncfusion:SfMultiColumnDropDownControl>

MVVM Code:
 private Company _selectedCompany;

        public Company SelectedCompany
        {
            get { return _selectedCompany; }
            set
            {
                if (value == _selectedCompany)
                {
                    return;
                }
                _selectedCompany = value;
                if (value != null)
                {
                    if (SelectedOrder != null)
                    {
                        SelectedOrder.ClientData = _selectedCompany;
                    }
                }
                NotifyOfPropertyChange(() => SelectedCompany);
            }
        }

Thats the Error:

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsBase.dll

   bei Syncfusion.UI.Xaml.Grid.SfMultiColumnDropDownControl.ProcessOnSelectedItemChanged(Object selectedItem)
   bei Syncfusion.UI.Xaml.Grid.SfMultiColumnDropDownControl.<.cctor>b__9(DependencyObject o, DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   bei System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   bei System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   bei System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   bei System.Windows.Data.BindingExpression.Activate(Object item)
   bei System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
   bei System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
   bei MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
   bei MS.Internal.Data.DataBindEngine.Run(Object arg)
   bei MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
   bei System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
   bei System.Windows.ContextLayoutManager.UpdateLayout()
   bei System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   bei System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   bei System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   bei System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   bei System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   bei System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
   bei System.Windows.Interop.HwndTarget.OnResize()
   bei System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

Thanks in advance

Many greetings from Germany
Wolfgang



Sowndaiyan Paulpandi [Syncfusion]
Replied On December 7, 2015 06:33 AM

Hi Feneberg,

Sorry for the delay caused.

We have analyzed your query with your provided code example. We are not able to reproduce the reported “NullReferenceException when set the SelectedItem in ViewModel”. For your reference we have attached the tested sample in the below sample location, please revert by modifying the attached sample based on your application along with the replication procedure. It will be helpful for us to analyze further. 


Sample Location: http://www.syncfusion.com/downloads/support/forum/121338/ze/MultiColumnDropDownDemo-1846307919

Regards,

Sowndaiyan


Feneberg
Replied On February 15, 2016 02:57 PM

Sorry for my late response.

The problem is fixed in the Version 13.4.0.53.

Thanks for the support.

Best regard.

Wolfgang

Sowndaiyan Paulpandi [Syncfusion]
Replied On February 16, 2016 06:17 AM

Hi Feneberg,

Thanks for the update.

Please let us know if you need further assistance.
Regards,
Sowndaiyan

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;