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

RadButton in DataTemplate in ListView

1 Answer 159 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jon asked on 16 May 2012, 01:14 AM
I have RadButton in a DataTemplate in a ListView. I have a command bound to the button that works fine.
But when I click my button, without selecting the row - i need to get the current row - how can I get the SelectedItem of the current ListView Row when the RadButton is clicked.   For example I want to name the Button REMOVE and remove the current row - without having to click 'behind' the RadButton to select the row to be deleted. first.




ListView x:Name="lstRangeColors" Width="225" MaxHeight="275" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0,0,0,0" ItemsSource="{Binding Path=Filters.RangeColors}" SelectedItem="{Binding Path=RangeColor}">









<ContentPresenter Margin="5,5,5,5" Content="{Binding}">









<Grid x:Name="gridContent" Height="35" VerticalAlignment="Stretch">






<ColumnDefinition Width="20*"/>



<ColumnDefinition Width="60*"/>



<ColumnDefinition Width="40*"/>









<RowDefinition Height="30" />






<CheckBox Grid.Row="0" Grid.Column="0" Width="40" IsChecked="{Binding RangeValue.IsSelected, Mode=TwoWay}" Margin="5,5,0,0"/>



<TextBox Grid.Row="0" Grid.Column="1" BorderBrush="Navy" BorderThickness="1" Width="40" Text="{Binding RangeValue, Mode=TwoWay}" Margin="15,0,0,0" FontSize="14" />



<<telerik:RadButton Grid.Row="0" Grid.Column="2" Height="30" Background="{Binding BlockColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}, Path=DataContext.SelectColorCommand}" HorizontalAlignment="Left" Margin="25,0,0,0" Name="btnColor" Width="40" />






















1 Answer, 1 is accepted

Sort by
Telerik team
answered on 18 May 2012, 05:13 PM
Hi Jon,
If you want to remove the row with command you can send the business object as CommandParameter:
<telerik:RadButton Name="btnColor"
                    Background="{Binding BlockColor,
                    Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}, Path=DataContext.SelectColorCommand}"
CommandParameter="{Binding }" />
I've attached a sample project that shows this so could you please examine it and if you have further questions feel free to ask.

the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question