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