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

Buttons in the grid

9 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
bkagan98
Top achievements
Rank 1
bkagan98 asked on 10 Apr 2011, 04:49 AM
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?

9 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 11 Apr 2011, 09:56 AM
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
0
bkagan98
Top achievements
Rank 1
answered on 11 Apr 2011, 02:16 PM
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.
0
Vanya Pavlova
Telerik team
answered on 11 Apr 2011, 03:28 PM
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
0
bkagan98
Top achievements
Rank 1
answered on 12 Apr 2011, 05:38 PM
Would you please provide a sample on how to do this? I am still new to Silverlight and Telerik controls... Thanks.
0
bkagan98
Top achievements
Rank 1
answered on 19 Apr 2011, 09:31 PM
I have tried different ways of finding a button inside a cell, but without any success. Would you please help me with this? Thanks.
0
Vanya Pavlova
Telerik team
answered on 19 Apr 2011, 09:56 PM
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
0
bkagan98
Top achievements
Rank 1
answered on 19 Apr 2011, 10:29 PM
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.
0
bkagan98
Top achievements
Rank 1
answered on 28 Apr 2011, 11:37 PM
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>

0
Josh
Top achievements
Rank 1
answered on 14 May 2011, 06:44 PM
Agreed Value converter FTW! 
Tags
GridView
Asked by
bkagan98
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
bkagan98
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Share this question
or