This is a migrated thread and some comments may be shown as answers.

Hide plus sign when no child relations exist

1 Answer 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gopinath
Top achievements
Rank 1
Gopinath asked on 09 Jun 2017, 10:51 AM
How to hide plus sign from RadGridView row, if no childrows exist ?

1 Answer, 1 is accepted

Sort by
0
Lance | Senior Manager Technical Support
Telerik team
answered on 14 Jun 2017, 02:00 PM
Hi Gopinath,

This forum post is a duplicate of the support ticket you've submitted, I will summarize my response so that  it is visible to the community. We can continue our conversation in the support ticket, as we have been doing, if you have any further questions.


Response:

The GridViewToggleRowDetailsColumn has no visibility into the DataContext of the row, thus it cannot determine if the row has RowDetails.  You would need to build a custom column, that can perform some logic on the bound item, to determine if the RadToggleButton should be visible or not.

Attached is a demo and here's the relevant logic to hide the button:

public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
    // 1 - create the UIElement that will be used for the "+" button
    var toggleButton = new GridViewToggleButton { Margin = new Thickness(3) };
  
    // 2 - Bind the DetailsRowVisibility property of the row to the IsChecked property of the ToggleButton
    var row = cell.ParentRow as GridViewRow;
    row?.SetBinding(GridViewRow.DetailsVisibilityProperty, new Binding("IsChecked") { Source = toggleButton, Converter = new BooleanToVisibilityConverter(), Mode = BindingMode.TwoWay });
              
    // 3 - Get the data item
    var book = dataItem as BookItemViewModel;
  
    // 4 - KEY POINT- Hide ToggleButton if you don't want to show it
    if (string.IsNullOrEmpty(book?.Summary)) 
            toggleButton.Visibility = Visibility.Collapsed;
  
    return toggleButton;
}


Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Gopinath
Top achievements
Rank 1
Answers by
Lance | Senior Manager Technical Support
Telerik team
Share this question
or