Disable GridViewToggleRowDetailsColumn for specific rows

9 posts, 1 answers
  1. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 24 Mar 2011 Link to this post

    Hi there,

    I use a RadGridView with a GridViewToggleRowDetailsColumn.

    The detailview for the row should be available when the value of a specific cell is 'True'.
    Otherwise the [+] button should be disabled.

    I tried to use the 'RowLoaded' event. But It's not working until the first column is out of sight.
    It seems that the indexer is switching.

    Could someone explain a better way to achieve this?


    Best regards
    Robin
  2. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 24 Mar 2011 Link to this post

    Hi,

    I found an example by Maya Zhecheva

    The Behavior is working fine, the IsExpandableProperty is bound and set to the right value of each GridViewRow.

    But the indicator [+] of the GridViewToggleRowDetailsColumn is still available/enabled.

    How can that be?

    I'm also confused that the XAML of Mayas example got no GridViewToggleRowDetailsColumn.
    Where is the [+] toggle then from?
  3. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 24 Mar 2011 Link to this post

    Hi Robin,

    I have also prepared a sample project that implements yet another possible solution to this case. Please, refer to it and inform us if this approach meets your requirements.
    As for the blog post, the visibility of the toggle button is bound to the IsExpandable property of a row. The child grid is displayed in a hierarchy, not in RowDetails. 


    Regards,
    Ivan Ivanov
    the Telerik team
  4. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 29 Mar 2011 Link to this post

    Hi Ivan,

    thanks for your reply.

    That approach is working in my project.
    But I'm wondering why the toggle button is not "grayed"?

    See the screenshot.
    (All toggle buttons are !IsEnabled)

    Best regards
    Robin
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 31 Mar 2011 Link to this post

    Hello Robin,

    Changing GridViewToggleButton's IsEnabled property doesn't affect the cell that nests it. You may try setting GridViewCell's IsEnabled property instead. Please, refer to the attached project.

    Greetings,
    Ivan Ivanov
    the Telerik team
  6. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 31 Mar 2011 Link to this post

    Hi Ivan,

    now it's working as expected.

    Thank you


    Robin
  7. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 07 Apr 2011 Link to this post

    Hi Ivan,

    it's still not working properly.

    The disabled Cell is kind of switching when user is scrolling the GridView.

    First screenshot: All works well
    Second screenshot: After scrolling

    Here my code for the RowLoaded Event:

    if (e.Row.Item != null)
          {
            if (e.Row.ChildrenOfType<GridViewCell>().First().Column.GetType() == typeof(GridViewToggleRowDetailsColumn))
            {
              if ((e.Row.Item as FaultCockpitEntry).Dispatched)
              {
                e.Row.ChildrenOfType<GridViewCell>().First().IsEnabled = true;
              }
              else
              {
                e.Row.ChildrenOfType<GridViewCell>().First().IsEnabled = false;
              }
            }
          }

    Greetings
    Robin
  8. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 07 Apr 2011 Link to this post

    Hi Robin,

    I have modified my initial project a bit. Please, have a look at it, and inform us if the new approach meets your requirements.

    All the best,
    Ivan Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Avi
    Avi avatar
    25 posts
    Member since:
    Oct 2010

    Posted 27 Dec 2011 Link to this post

    Hi,

    I tried as Robin to use  'RowLoaded' event to effect IsEnabled / IsExpandable property, but with no success.
    Here is my code :
    private void RefundsGrid_RowLoaded(object sender, RowLoadedEventArgs e)
            {
                if (e.DataElement != null)
                {
                    
                    GridViewRow row = e.Row as GridViewRow;
                    Refund refund = (Refund)e.DataElement;
                    if (row != null && refund != null)
                    {
                       row.IsExpandable = refund.IsDivided;
     
                       OR
     
                       e.Row.ChildrenOfType<GridViewCell>()[1].ChildrenOfType<GridViewToggleButton>().First().IsEnabled =  refund.IsDivided;
                    }
                }
            }
      <UserControl.Resources>      
            <DataTemplate x:Key="RefundProvisionsGridCell">
                <uc:RefundProvisionsGrid />
            </DataTemplate>
    </UserControl.Resources>
     
     <telerik:RadGridView Name="RefundsGrid" ItemsSource="{Binding Refunds}" RowDetailsTemplate="{StaticResource RefundProvisionsGridCell}" RowLoaded="RefundsGrid_RowLoaded" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="{Binding AppStrings.Selection, Source={StaticResource StringsLocator}}"
                                            HeaderTextAlignment="Center"
                                            IsFilterable="False"
                                            IsResizable="False"
                                            IsSortable="False">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox HorizontalAlignment="Center"
                                      IsChecked="{Binding IsSelected, Mode=TwoWay}"
                                      IsEnabled="{Binding RelatedPolicy.RelatedCustomer.HasRefunds,Converter={StaticResource invertedBooleanConverter}}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>        
                <telerik:GridViewToggleRowDetailsColumn Width="10" IsResizable="False" />
               </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    It's not working. it shows the "+" icon all the time and you can expend it although it get "false" value. 
    What am I doing wrong ?

    Thanks
Back to Top