Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi all

<DataGrid AutoGenerateColumns="False" Height="141" HorizontalAlignment="Left" Margin="114,109,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="353" ItemsSource="{Binding}" >
    <DataGridTextColumn Header="Alias" Binding="{Binding ItemAdAlias}" Width="50"/>
  <DataGridTextColumn Header="Min Stock" Binding="{Binding ItemAdMin}" Width="60"/>
 <DataGridTextColumn Header="Max Stock" Binding="{Binding ItemAdMax}"/>
 <DataGridTextColumn Header="Current Stock" Binding="{Binding ItemAdCurr}"/>
 <DataGridTextColumn Header="Color" Binding="{Binding ItemAdColor}"/>
 <DataGridTextColumn Header="Set" Binding="{Binding ItemAdSet}"/>
 <DataGridTextColumn Header="Remarks" Binding="{Binding ItemAdRemarks}"/>

This is my datagrid my application.
now i have to add another row with checkboxes corresponding to each column and on check and uncheck save and fetch the value from the database.

Please tell me how to do this..
or any other alternate idea will be helpful.

Thank you
Updated 23-Oct-17 4:16am

You can use the DataGridCheckBoxColumn or a DataGridTemplateColumn with a CheckBox inside. Check these links to get an idea how to do that.
adding the checkbox column in to WPF datagrid and select the checked rows [^]
Add checkbox in WPF Datagrid DatagridTemplateColumnHeader[^]
Share this answer
<wpf:DataGridTemplateColumn Width="SizeToHeader" IsReadOnly="True" Header="First Selection">
            <CheckBox IsChecked="{Binding Path=First}"  Checked="OnChecked" Margin="2,0,2,0" HorizontalAlignment="Center" VerticalAlignment="Stretch" />

You can use template column to add checkbox in datagrid .
Share this answer
Member 11437473 21-Feb-15 2:10am    
How to read the check box status in c# for above code.
I went with very simple..

<DataGridCheckBoxColumn Binding="{Binding IsChecked, Mode=TwoWay}" IsReadOnly="False">
                                        <CheckBox Checked="FieldDataGridChecked" Unchecked="FieldDataGridUnchecked" Margin="2" />

Just handle the checked and unchecked events, and apply the "checked" to the model.

private void FieldDataGridChecked(object sender, RoutedEventArgs e)
            foreach (FieldViewModel model in _fields)
                model.IsChecked = true;

        private void FieldDataGridUnchecked(object sender, RoutedEventArgs e)
            foreach (FieldViewModel model in _fields)
                model.IsChecked = false;
Share this answer
CHill60 23-Oct-17 17:47pm    
However, over 4 years ago the OP went with solution 1. Stick to answering new questions where the OP still needs help
pccoder71 5-Jan-18 10:05am    
yes, he did, but that doesn't mean my example won't help others.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900