If i understand Correctly, yo need a select all checkbox in your listview.
Below is the template and code for same.
<Grid>
<ListView x:Name="lv">
<ListView.View>
<GridView x:Name="gv">
<GridViewColumn x:Name="gridClm_SelectRow" Width="35">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cbSelectRow" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}}, Path=IsSelected}"
HorizontalContentAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" Checked="chkWspSelect_Checked" Unchecked="chkWspSelect_Unchecked" IsThreeState="False"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
<CheckBox Margin="0" x:Name="chkSelectAll" Click="chkSelectAll_Click"/>
</GridViewColumn>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
public partial class MainWindow : Window
{
public ObservableCollection<MyEmployeeClass> EmployeeList { get; set; }
public MainWindow()
{
InitializeComponent();
EmployeeList = new ObservableCollection<MyEmployeeClass>();
EmployeeList.Add(new MyEmployeeClass("Parth1"));
EmployeeList.Add(new MyEmployeeClass("Parth2"));
EmployeeList.Add(new MyEmployeeClass("Parth3"));
EmployeeList.Add(new MyEmployeeClass("Parth4"));
EmployeeList.Add(new MyEmployeeClass("Parth5"));
EmployeeList.Add(new MyEmployeeClass("Parth6"));
EmployeeList.Add(new MyEmployeeClass("Parth7"));
lv.ItemsSource = EmployeeList;
}
private void chkSelectAll_Click(object sender, RoutedEventArgs e)
{
if (chkSelectAll.IsChecked.Value == true)
{
lv.SelectAll();
}
else
{
lv.UnselectAll();
}
}
private void chkWspSelect_Checked(object sender, RoutedEventArgs e)
{
ListBoxItem item = ItemsControl.ContainerFromElement(lv, e.OriginalSource as DependencyObject) as ListBoxItem;
if (item != null)
{
item.IsSelected = true;
}
}
private static bool individualChkBxUnCheckedFlag { get; set; }
private void chkWspSelect_Unchecked(object sender, RoutedEventArgs e)
{
ListBoxItem item = ItemsControl.ContainerFromElement(lv, e.OriginalSource as DependencyObject) as ListBoxItem;
if (item != null)
item.IsSelected = false;
individualChkBxUnCheckedFlag = true;
CheckBox headerChk = (CheckBox)((GridView)lv.View).Columns[0].Header;
headerChk.IsChecked = false;
}
}
public class MyEmployeeClass
{
public string Name { get; set; }
public MyEmployeeClass(string name)
{
Name = name;
}
}
PS : You can move Methods in code behind to ViewModel in case of MVVM :)