Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
How to get the selected row item in XamDatagrid
posted

Below is my xaml

<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<ListBox x:Name="movieList" ItemsSource="{Binding Path=MovieMain.Movies}" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

<StackPanel Grid.Column="1" Margin="10">
<StackPanel Orientation="Horizontal">
<Label Content="Selected movie: " Margin="2" />
<Label Content="{Binding Path=SelectedItem.Name, ElementName=movieList}" />
</StackPanel>

<igDP:XamDataGrid x:Name="dataGrid" DataSource="{Binding Path=SelectedItem.Artists, ElementName=movieList}">

<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>

<igDP:ComboBoxField Name="Name">
<igDP:ComboBoxField.EditorStyle>
<Style TargetType="igEditors:XamComboEditor">
<Setter Property="ItemsSource"
Value="{Binding Path=DataContext.ComboItems, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />
</Style>
</igDP:ComboBoxField.EditorStyle>
</igDP:ComboBoxField>

<igDP:NumericField Name="Age" />

</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>

</igDP:XamDataGrid>
</StackPanel>

<Button Grid.Row="1" Grid.Column="0" Width="55" Height="25" Command="{Binding ClickCommand}"/>

</Grid>

In above I bind Listbox with one model and based on selected item I am binding datagrid.

Now I am doing delete operation on datagrid. So how can we achieve the delete funtionality?

  • 2490
    Offline posted

    Hello Yugandhar,

    Thank you for the code snippet you have provided.

    You can use DataPresenterCommands, a complete list of commands you can find in the documentation here. You can bind the button directly to the XamDataGrid, e.g.:


          <Button Grid.Row="1" Grid.Column="0" Width="55" Height="25"
                        Command="{x:Static igDP:DataPresenterCommands.DeleteSelectedDataRecords}"
                        CommandTarget="{Binding ElementName=dataGrid}"/>

    In order to successfully delete a record, it has to be selected beforehand.

    To see these commands in action, view the sample in WPF Samples Browser under the xamDataGrid category called "xamDataGrid Commands."