TransWikia.com

Get data from DataGrid if DataGridCheckBoxColumn is checked

Stack Overflow Asked by user12711263 on November 4, 2021

I have this XAML:

<Window x:Name="Form" x:Class="SanityArchiver.DesktopUI.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SanityArchiver.DesktopUI.Views"
        xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        mc:Ignorable="d"
        Title="Sanity Archiver" Height="450" Width="800">
    <Grid x:Name="MainWindow1" Loaded="Window_Loaded">

        <Grid.Resources>

            <HierarchicalDataTemplate DataType="{x:Type local:Directory}" ItemsSource ="{Binding Directories}">

                <TextBlock Text="{Binding Path=Name}" MouseDown="NameCol_mousedown"/>

            </HierarchicalDataTemplate>

        </Grid.Resources>
        <TreeView Margin="12,12,0,12" Name="treeView1" HorizontalAlignment="Left" Width="204" >

            <TreeViewItem ItemsSource="{Binding Directories}" Header="Choose directory"/>

        </TreeView>
        <DataGrid x:Name="FilesDataGrid" AutoGenerateColumns="False" Margin="234,12,10.286,50.714">

            <DataGrid.Columns>
                <DataGridCheckBoxColumn x:Name="CheckBox" Header="" Binding="{Binding IsChecked}"/>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding FileName}" Header="Name" Width="200"/>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Created}" Header="Created" Width="200"/>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Size}" Header="Size(kb)" Width="200"/>
            </DataGrid.Columns>

        </DataGrid>

            <Button x:Name="CompressButton" Content="Compress" HorizontalAlignment="Left" Margin="234,389,0,0" VerticalAlignment="Top" Width="75" Click="CompressButton_Click"/>
    </Grid>
</Window>

And if the CheckBox is checked(it can be one file or any number) and I click the "Compress" button, I would like to get back the rows which is checked. If it isn’t doable in DataGrid, could you point me in another direction?

Thanks

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP