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

How to show RowDetails based on button?

1 Answer 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
saravanakumar subramaniam
Top achievements
Rank 1
saravanakumar subramaniam asked on 23 May 2011, 01:47 AM
Hi,
I am using RadGrid with 5 columns, in which one of the column hold Button. Click event of the button is binded using Command using MVVM model .eg(MyButtonCommand). when i click this button i need to show the RowDetailsTemplate. RowDetailsTemplate shows the some information about the row, but i don't have control to bring the Rowdetails when i click the button.

Is there anyway that i can show the RowDetails based on button inside the grid?

1 Answer, 1 is accepted

Sort by
0
Adam Marshall
Top achievements
Rank 1
answered on 23 May 2011, 02:08 AM
Hi there saravanakumar,

I had the same requirement too.

I created a Converter which was bound to a boolean (ShowRowDetails) on my ViewModel.

[ValueConversion(typeof(Boolean), typeof(GridViewRowDetailsVisibilityMode))]
public class BoolToRowVisibilityConverter : IValueConverter
{
    #region IValueConverter implementation
    /// <summary>
    /// Converts Boolean to RowDetailsVisibility
    /// </summary>
    public object Convert(object value, Type targetType, 
        object parameter, CultureInfo culture)
    {
        if (value == null)
            return Binding.DoNothing;
        if (parameter == null)
            return Binding.DoNothing;
        Boolean input = false;
        Boolean.TryParse(value.ToString(), out input);
        Boolean invertActive = false;
        Boolean.TryParse(parameter.ToString(), out invertActive);
        if (input)
        {
            return invertActive ? GridViewRowDetailsVisibilityMode.VisibleWhenSelected : GridViewRowDetailsVisibilityMode.Collapsed;
        }
        else
            return invertActive ? GridViewRowDetailsVisibilityMode.Collapsed : GridViewRowDetailsVisibilityMode.VisibleWhenSelected;
    }
    /// <summary>
    /// Convert back, but its not implemented
    /// </summary>
    public object ConvertBack(object value, Type targetType, 
        object parameter, CultureInfo culture)
    {
        throw new NotImplementedException("Not implemented");
    }
    #endregion
}

There is a property on the RadGridView which specifies whether to show or hide the row details.

<telerik:RadGridView  RowDetailsVisibilityMode="{Binding ShowRowDetails, Converter={StaticResource BoolToRowVisibilityConv}, ConverterParameter=True}" />

I then had a button with a Command on my ViewModel which set this property (and did other things) when clicked.

<Button Command="{Binding ToggleRowDetailsCommand}" />


Hope this helps.

Adam
Tags
GridView
Asked by
saravanakumar subramaniam
Top achievements
Rank 1
Answers by
Adam Marshall
Top achievements
Rank 1
Share this question
or