Wiki Link: [discussion:40365]
Problem binding RibbonComboBox to a DataTable  


Nov 20 2008 at 7:33 PM
Hi,
There seems to be a problem when I bind a RibbonComboBox to a System.Data.DataTable.  Here's my RibbonComboBox (the DataContext of the combobox is set to the datatable and 'Year' is a column in the datatable)

 <r:RibbonComboBox x:Name="ribbonComboBox" IsEditable="True" ItemsSource="{Binding}" 
                                      Width="75" SelectedValuePath="Year">
    <r:RibbonComboBox.ItemTemplate>
        
<DataTemplate>
            
<TextBlock Text="{Binding Year}" />
        
</DataTemplate>
    
</r:RibbonComboBox.ItemTemplate>
</r:RibbonComboBox>

 This works good, but when I select an item from the RibbonComboBox I get this exception:

System.InvalidCastException was unhandled
  Message="Unable to cast object of type 'System.Data.DataRowView' to type 'Microsoft.Windows.Controls.Ribbon.RibbonComboBoxItem'."
  Source="RibbonControlsLibrary"
  StackTrace:
       at Microsoft.Windows.Controls.Ribbon.RibbonComboBox.GetHighlightedComboBoxItem()
       at Microsoft.Windows.Controls.Ribbon.RibbonComboBox.OnSelectionChanged(SelectionChangedEventArgs e)
       at System.Windows.Controls.Primitives.Selector.InvokeSelectionChanged(List`1 unselectedItems, List`1 selectedItems)
       at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
       at System.Windows.Controls.Primitives.Selector.SelectionChanger.SelectJustThisItem(Object item, Boolean assumeInItemsCollection)
       at System.Windows.Controls.ComboBox.NotifyComboBoxItemMouseUp(ComboBoxItem comboBoxItem)
       at System.Windows.Controls.ComboBoxItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at SeedToHarvest.App.Main() in C:\Users\Alex\Documents\Visual Studio 2008\Projects\SeedToHarvest\SeedToHarvest\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 Everything works fine when I use a regular ComboBox instead, so is there is something else I need to do when using a RibbonComboBox, or is it a bug?

Thanks,
Alex


Nov 22 2008 at 7:06 PM
I have the exact same problem only mine is trying to do an ObservableCollection<string> bound to the control.

Is there anybody who has a workaround for this problem?

Nov 25 2008 at 2:55 AM
Thanks for reporting this issue.  This is a known issue and will be addressed in our V1 release.  In the meantime, unfortunately, you'll only be able to bind to collections of type RibbonComboBoxItem until we release a fix.

Nov 25 2008 at 9:31 PM
Hi,

I have the same problem, but now, even using a RibbonComboBoxItem I cannot get anything to display in the SelectionBox. The list displays OK when you click the drop down button, but I cannot get anything to appear in the SelectionBox. I have tried various things:

 

RibbonComboBox cb = mw.RibbonGrouping.FindName("Combo1") as RibbonComboBox;

 

 

List<RibbonComboBoxItem> list = new List<RibbonComboBoxItem>();

 

 

RibbonComboBoxItem rcbi = new RibbonComboBoxItem();

 

rcbi.Content =

"xyz";

 

list.Add(rcbi);

 

//cb.Items.Add(rcbi);

 

cb.ItemsSource = list;

cb.SelectedIndex = 0;

 

//cb.SelectedValue = rcbi;

 

 

//cb.SelectedItem = rcbi;




I think I must be missing something obvious, can someone point it out to me please?

Thanks

 


Nov 25 2008 at 10:48 PM
Edited Nov 25 2008 at 10:51 PM
Hi ChangedDaily,

I had the same problem and and setting IsEditable to true fixed it for me.  On this thread I found that there is a known problem with the IsEditable property.  But doing this doesn't fix the problem with binding to a DataTable.

Alex

Nov 26 2008 at 5:37 PM
Thanks - that fixed the problem I was having, I had spent some time on that!


Wed at 10:50 AM
Edited Wed at 10:50 AM

Has this issue been addressed yet?

I get exactly the same exception trying to bind to a List of strings!!

 


Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987