xaml code:
<Window x:Class="WpfApplication5.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3" Height="300" Width="300" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Grid>
<DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="33,20,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="hcb" Checked="hcb_Checked" Unchecked="hcb_Unchecked"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cb" Width="50" IsChecked="{Binding Path = c , Mode = TwoWay}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding s}" Header="NAME" Width="150"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication5
{
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
}
#region
ServiceReference1.ServiceClient o = new ServiceReference1.ServiceClient();
#endregion
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<xx> obj = new List<xx>();
for (int i = 0; i < o.view().ToList().Count;i++ )
{
xx y = new xx();
y.s = o.view().ToList()[i].NAME;
y.c = false;
obj.Add(y);
}
dataGrid1.ItemsSource = obj;
}
public class xx
{
public string s
{
get;
set;
}
public bool c
{
get;
set;
}
}
private void hcb_Checked(object sender, RoutedEventArgs e)
{
List<xx> obj = new List<xx>();
for (int i = 0; i < o.view().ToList().Count; i++)
{
xx y = new xx();
y.s = o.view().ToList()[i].NAME;
y.c = true;
obj.Add(y);
}
dataGrid1.ItemsSource = obj;
}
private void hcb_Unchecked(object sender, RoutedEventArgs e)
{
List<xx> obj = new List<xx>();
for (int i = 0; i < o.view().ToList().Count; i++)
{
xx y = new xx();
y.s = o.view().ToList()[i].NAME;
y.c = false;
obj.Add(y);
}
dataGrid1.ItemsSource = obj;
}
}
}