C1 Treeview and C1 Datagrid selection synchonization

Posted by: mayur.purandare on 9 November 2017, 4:54 pm EST

    • Post Options:
    • Link

    Posted 9 November 2017, 4:54 pm EST

    Hello,

    I am using C1 Treeview and C1 Datagrid in my project.

    When I select any Item from the treeview, corresponding row in the datagrid is selected.

    Is there any way that the selection in the datagrid can be reflected in the treeview?

  • Posted 12 November 2017, 4:40 pm EST

    Hi,

    It’s a real pain for some strange reason, you have to use ContainerFromItem to get the container, then invoke the IsSelected property to get or set whether a C1.WPF.C1TreeViewItem control is selected.

    private void Treeview_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                selectedPerson = (treeview.SelectedItem.DataContext as Person);
                datatree.SelectedItem = SelectedPerson;
            }
    
            private void Datatree_SelectionChanged(object sender, C1.WPF.DataGrid.DataGridSelectionChangedEventArgs e)
            {
                selectedPerson = (datatree.SelectedItem as Person);
                C1TreeViewItem item = treeview.ItemContainerGenerator.ContainerFromItem(SelectedPerson) as C1TreeViewItem;
                item.IsSelected = true;
            }
    

    Also, find a sample application attached for complete implementation.

    Thanks,

    Singh

    SelectionInC1TreeView.zip

  • Posted 12 November 2017, 6:06 pm EST

    Thank you for the reply.

    I’ll check this and will get back to you.

    ~Mayur

  • Posted 13 November 2017, 4:48 pm EST

    Hello,

    I am using MVVM in the project.

    Attached is the sample code where I tried to sync the treeview and datagrid selection.

    However, when I copied same code to my Project it is giving me following exception.

    Message : Object reference not set to an instance of an object.

    Source : C1.WPF.DataGrid.4

    Stack Trace:

    at C1.WPF.DataGrid.DataGridView.#41g(DataGridCell #Nc, EventArgs #tQ, Boolean #51g)

    at C1.WPF.DataGrid.DataGridView.#Y1g(Object #BQ, C1TappedEventArgs #tQ)

    at C1.WPF.C1TapHelper.#ftg(Object #BQ, RoutedEventArgs #tQ)

    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.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.RaiseTrustedEvent(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, WindowMessage 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, Int32 numArgs)

    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    TreeViewDatagridSync.zip

  • Posted 13 November 2017, 4:49 pm EST

    Attaching the error file

  • Posted 13 November 2017, 5:28 pm EST

    Hi,

    I could not replicate the issue with the latest build. which can be downloaded from the link below:

    http://prerelease.componentone.com/dotnet40/C1WPFLibrary/2017-T3/C1WPFBasicLibrary.4_4.0.20173.578.zip

    See the attached screenshots for your sample.

    Thanks,

    Singh

  • Posted 19 November 2017, 4:35 pm EST

    Thanks a lot.

    ~Mayur

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels