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

RadButton in DataTemplate in ListView

1 Answer 78 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 16 May 2012, 01:14 AM
Hi..
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.
thanks!!!!!!!!!!!!!!!!!


<

 

 

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}">

 

 

<ListView.ItemTemplate>

 

 

<DataTemplate>

 

 

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

 

 

<ContentPresenter.ContentTemplate>

 

 

<DataTemplate>

 

 

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

 

 

<Grid.ColumnDefinitions>

 

 

<ColumnDefinition Width="20*"/>

 

 

<ColumnDefinition Width="60*"/>

 

 

<ColumnDefinition Width="40*"/>

 

 

</Grid.ColumnDefinitions>

 

 

<Grid.RowDefinitions>

 

 

<RowDefinition Height="30" />

 

 

</Grid.RowDefinitions>

 

 

<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" />

 

 

</Grid>

 

 

</DataTemplate>

 

 

</ContentPresenter.ContentTemplate>

 

 

</ContentPresenter>

 

 

</DataTemplate>

 

 

</ListView.ItemTemplate>

 

 

</ListView>


1 Answer, 1 is accepted

Sort by
0
Zarko
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"
                    Grid.Row="0"
                    Grid.Column="2"
                    Width="40"
                    Height="30"
                    Margin="25,0,0,0"
                    HorizontalAlignment="Left"
                    Background="{Binding BlockColor,
                               Mode=TwoWay,
                               UpdateSourceTrigger=PropertyChanged}"
                    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.

Greetings,
Zarko
the Telerik team

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

Tags
Buttons
Asked by
Jon
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or