Home Forums WPF controls Xceed DataGrid for WPF Custom Cell Editors – RichTextBox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23924 |

    Can anyone show an example of how to use Xceed WPF DataGrid’s Custom Cell Editors to edit a cell with a RichTextBox control. Is it possible to bind to RichTextBox ?
    Thank you very much for a nice product.
    Amit

    Imported from legacy forums. Posted by Amit (had 770 views)

    User (Old forums)
    Member
    Post count: 23064

    The documentation is fairly clear on this. If you need to do it in code there are some forum posts that can help you along.

    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Custom%20Cell%20Editors.html

    Here’s some basic boiler plate for doing it in code:
    <code>
    static public CellEditor GetCellEditorFromType(Type cellEditorType, DependencyProperty editorValueProperty)
    {
    try
    {
    CellEditor cellEditor = new CellEditor();
    FrameworkElementFactory fweFactory = new FrameworkElementFactory(cellEditorType);

    if (editorValueProperty != null)
    {
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();
    fweFactory.SetBinding(editorValueProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }

    DataTemplate template = new DataTemplate(cellEditorType);
    template.VisualTree = fweFactory;
    cellEditor.EditTemplate = template;

    return cellEditor;

    }
    catch (Exception ex)
    {
    Console.WriteLine(“\n*\n* Error: Unable to create cell editor from type ({0})\n* Exception:{1}\n*”, cellEditorType.ToString(), ex.Message);
    return null;
    }
    }

    </code>

    In my code I’ll use this as follows:
    col.CellEditor = GetCellEditorFromType(typeof(PopupTextBox), PopupTextBox.PopupTextProperty);

    Where PopTextBox is a custom Control I’ve written, but you could use any control where you need to bind the cell value to a single dependency property in the control.

    Imported from legacy forums. Posted by Richard (had 842 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m aware of the doc, still RichTextBox control is not simple to bind to, since it doesn’t have single content dependency property. I also note that I wish to do this in XAML rather than code.

    The post at
    http://forums.xceed.com/forums/ShowPost.aspx?PostID=7059

    also claim that it is not trivial and might be a bug.

    Imported from legacy forums. Posted by Amit (had 355 views)

    User (Old forums)
    Member
    Post count: 23064

    Interesting problem, seems like the #7059 forum post identifies a bug with FrameworkContentElements. The RichTextBox’s Document is a FlowDocument which of course is a FreameworkContentElement.

    It’s curious, to me, however that the forum post #7059 doesn’t set the document property at all. It might be interesting to play around with the #7059 code and insert something for the Document property to see what happens.

    The 7059 poster sounds like their are going to use a popup to display/edit the RichTextBox. Maybe that idea could work for you too. But obviously this isn’t ideal if your main objective is to “display” the document in the grid.

    I’m glad you’ve pointed this out because I need to use RichTextBox in some of my grids also.

    It would be interesting to see if the latest build, v1.1.7326.14130, changes anything. I believe post #7059 may have been written prior to that release.

    I understand v1.2 is coming soon so maybe that will help. It would be good if there was a bug list we could consult and see which version fixed what and when outstanding bug fixes might be expected.

    When I start looking at RichTextBox editiors I’ll post anything I learn.

    Good Luck,
    Richie

    Imported from legacy forums. Posted by Richard (had 267 views)

    User (Old forums)
    Member
    Post count: 23064

    I couldn’t find a work around the bug posted in #7059.

    I hope this gets fixed in v1.2.

    For my test case I can edit the RichtTextBox one time. On any subsequent edit the crash below occurs.

    Unhandled Exception: System.InvalidOperationException: ‘System.Windows.Documents.Paragraph’ is not a Visual or Visual3D.
    at MS.Internal.Media.VisualTreeUtils.AsVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
    at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
    at Xceed.Wpf.DataGrid.DataGridControl.IsPartOfElement(DependencyObject referenceObject, DependencyObject sourceObject)
    at Xceed.Wpf.DataGrid.DataGridControl.OnPreviewMouseDown(MouseButtonEventArgs e)
    at System.Windows.UIElement.OnPreviewMouseDownThunk(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.ContentElement.RaiseEventImpl(RoutedEventArgs args)
    at System.Windows.ContentElement.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 action
    s, Int32 x, Int32 y, Int32 wheel)
    at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& han
    dled)
    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 isSingleParamete
    r, Delegate catchHandler)
    at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Bo
    olean 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.RunInternal(Window window)
    at System.Windows.Application.Run(Window window)
    at System.Windows.Application.Run()
    at ComboBoxEditorForClassField.App.Main() in M:\dev\ITToolerDev\WPF\XceedTests\ComboBoxEditorForClassField\obj\Debug\App.g.cs:lin
    e 0

    Imported from legacy forums. Posted by Richard (had 4293 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.