Hello,
Could you please specify how can a button placed in the CellTemplate tag of a GridViewDataColumn (1) map the row in which the button is placed at click?
In my implementation, I need to embed buttons in each row of a specific column in order to remove those rows. The button is bound to a command which removes the CurrentItem from the ListCollectionView bound to the GridView (2).
However, clicking the embedded button doesn't mark its row as the selected one and the command removes the row which is marked as Selected in the GridView (by clicking on one of the columns which don't embed the mentioned button).
In conclusion, the button is supposed to mark its row as selected when clikcked, in order for the bound Command to remove the desired row, without having to click on the row (thus selecting it) and then click on the button.
Could you please specify how can a button placed in the CellTemplate tag of a GridViewDataColumn (1) map the row in which the button is placed at click?
In my implementation, I need to embed buttons in each row of a specific column in order to remove those rows. The button is bound to a command which removes the CurrentItem from the ListCollectionView bound to the GridView (2).
However, clicking the embedded button doesn't mark its row as the selected one and the command removes the row which is marked as Selected in the GridView (by clicking on one of the columns which don't embed the mentioned button).
In conclusion, the button is supposed to mark its row as selected when clikcked, in order for the bound Command to remove the desired row, without having to click on the row (thus selecting it) and then click on the button.
7 Answers, 1 is accepted
0
Sorin
Top achievements
Rank 1
answered on 05 Dec 2014, 04:16 PM
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton
Content="Remove"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Height="21"
Width="Auto"
IsEnabled="{Binding DataContext.IsEditState, RelativeSource={RelativeSource AncestorType=UserControl}}"
Command="{Binding Path=DataContext.RemoveCurrentBlockedIntervalCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
Visibility="Visible" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton
Content="Remove"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Height="21"
Width="Auto"
IsEnabled="{Binding DataContext.IsEditState, RelativeSource={RelativeSource AncestorType=UserControl}}"
Command="{Binding Path=DataContext.RemoveCurrentBlockedIntervalCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
Visibility="Visible" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
0
Sorin
Top achievements
Rank 1
answered on 08 Dec 2014, 07:31 AM
Posted above is the RadGridView column's source code.
0
Hello Sorin,
A possible way to avoid the need of selecting the row and delete it directly when you click the button is to take advantage of the built in RadGridViewCommands, like so:
For more information about the RadGridViewCommands, you can check the Overview and Implementation articles of the Commands section of our documentation about RadGridView.
Please let us know if this approach is suitable to your scenario.
Regards,
Boris
Telerik
A possible way to avoid the need of selecting the row and delete it directly when you click the button is to take advantage of the built in RadGridViewCommands, like so:
<
telerik:GridViewColumn
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
telerik:RadButton
Content
=
"Delete"
Command
=
"telerik:RadGridViewCommands.Delete"
CommandParameter
=
"{Binding}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
For more information about the RadGridViewCommands, you can check the Overview and Implementation articles of the Commands section of our documentation about RadGridView.
Please let us know if this approach is suitable to your scenario.
Regards,
Boris
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Sorin
Top achievements
Rank 1
answered on 08 Dec 2014, 02:12 PM
Hello again,
I created a button in the Data Template exactly as you described, but the Delete buttons are disabled. Not even setting IsEnabled to true doesn't enable the buttons. Any idea why?
Thanks!
I created a button in the Data Template exactly as you described, but the Delete buttons are disabled. Not even setting IsEnabled to true doesn't enable the buttons. Any idea why?
Thanks!
0
Accepted
Hi Sorin,
Another possible reason for the buttons to be disabled, even it their IsEnabled property is set to True, is that the entire RadGridView is disabled as well. In order to investigate further why this behavior could you please provide us with a small runnable project that reproduces the issue ?
Please keep in mind that to send us the project you will need to open a new support ticket.
Regards,
Boris
Telerik
Another possible reason for the buttons to be disabled, even it their IsEnabled property is set to True, is that the entire RadGridView is disabled as well. In order to investigate further why this behavior could you please provide us with a small runnable project that reproduces the issue ?
Please keep in mind that to send us the project you will need to open a new support ticket.
Regards,
Boris
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Sorin
Top achievements
Rank 1
answered on 10 Dec 2014, 09:16 AM
+attachment
0
Hello Sorin,
In order to investigate further why this behavior occurs could you please provide us with a small runnable project that reproduces the issue ? By providing us with such a project we will be able to debug it on our side and inform you of our findings. In addition, if you are not entirely sure how to isolate it, you can check this Isolating a problem in a sample project blog post for some guidance.
Regards,
Boris
Telerik
In order to investigate further why this behavior occurs could you please provide us with a small runnable project that reproduces the issue ? By providing us with such a project we will be able to debug it on our side and inform you of our findings. In addition, if you are not entirely sure how to isolate it, you can check this Isolating a problem in a sample project blog post for some guidance.
Regards,
Boris
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.