Buttons in the grid

10 posts, 0 answers
  1. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 09 Apr 2011 Link to this post

    Last column in my RadGridView contains RadButtons. For my application I need to hide a button in a row after user clicks on it and confirms their intent to perform an action. How to find that button in the grid?
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 11 Apr 2011 Link to this post

    Hello Boris,

     

    May you please elabore a little bit more on your scenario? You have defined a RadButton within a GridViewColumn's CellTemplate, but I am not quite sure what should be hidden, the parent row of this button or the button itself? 

    You may also take a look at our Commands demo for further reference and at the following help article.


    Greetings,
    Vanya Pavlova
    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
  3. DevCraft banner
  4. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 11 Apr 2011 Link to this post

    This grid contains a list of pending jobs. User has the ability to cancel any of them by pressing corresponding 'Cancel' button. So, he presses 'Cancel' button, confirms his intent in popup window. Then the database gets updated with new status. What we want to do is to 'hide' the button right after that, but I have problem finding that button control in the cell.
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 11 Apr 2011 Link to this post

    Hi Boris,

     

    You may use the extension methods ParentOfType/ChildrenOfType to find that button and hide it by setting its Visibility property to Collapsed based on a condition, refer to the following article. 


    Greetings,
    Vanya Pavlova
    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
  6. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 12 Apr 2011 Link to this post

    Would you please provide a sample on how to do this? I am still new to Silverlight and Telerik controls... Thanks.
  7. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 19 Apr 2011 Link to this post

    I have tried different ways of finding a button inside a cell, but without any success. Would you please help me with this? Thanks.
  8. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 19 Apr 2011 Link to this post

    Hi Boris,

     

    Within the Button Click event handler you may execute your custom code and finally set the Visibility property to Collapsed. You may extend this behavior in a variety of scenarios based on your custom logic.
    The following snippet sets the Background of the parent row to some color and finally hides this button, please refer to the following:

    <telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Change Parent Row" Click="RadButton_Click" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn>

    private void RadButton_Click(object sender, RoutedEventArgs e)
            {
                var button = sender as RadButton;
                    //Here you may open some dialog and execute some custom code                   //based on the DialogResult, this is just for demonstration purpose
                var row = button.ParentOfType<GridViewRow>();
                if(row != null)
                {
                     row.Background = new SolidColorBrush(Colors.Red);     
                }
                button.Visibility=Visibility.Collapsed;
            }


    Feel free to change it in the way you need.
    Please give it a try and let me know if you need any further assistance.

    All the best,
    Vanya Pavlova
    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. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 19 Apr 2011 Link to this post

    The problem is, that inside Button_Click method I use RadWindow.Confirm() to ask user's confirmation and don't know how to get a reference (from inside OnClosed event) to the grid/row/cell/and finally the button that I pressed.
  10. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 28 Apr 2011 Link to this post

    I found that it is much easier and faster to control the visibility of the button by using of converter:

    <telerik:GridViewDataColumn x:Name="Action" UniqueName="Action" 
                    DataMemberBinding="{Binding JobStatusID, Mode=OneWay}"
                     IsFilterable="False" IsGroupable="False" Width="75">
            <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                    <telerik:RadButton x:Name="btnCancel" Content="Cancel"
                            Click="btnCancel_Click"
                            Visibility="{Binding JobStatusID, Converter={StaticResource StatusToVisibilityConverter}}"/>
            </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>

  11. Josh Nielson
    Josh Nielson avatar
    11 posts
    Member since:
    May 2010

    Posted 14 May 2011 Link to this post

    Agreed Value converter FTW! 
Back to Top
DevCraft banner