private void Checked(object sender, RoutedEventArgs e) { if (_isLoading) { return; } try { var checkbox = (CheckBox)sender; var value = Convert.ToString(checkbox.Content); if (Convert.ToString(checkbox.Tag) != "(Select All)") { AutoFilterHelper.ApplyFilters(CurrentGrid, CurrentColumn, value); } else { _isLoading = true; var distictictValues = AutoFilterHelper.CurrentDistictValues; foreach (var distictictValue in distictictValues) { if (distictictValue.Name != "(Select All)" && distictictValue.IsSelectAll != "(Select All)") { distictictValue.IsChecked = true; } } AutoFilterHelper.CurrentDistictValues = distictictValues; AutoFilterHelper.RemoveAllFilter(CurrentGrid, CurrentColumn); foreach (var c in distictictValues) { c.IsChecked = true; } var sp1 = FindControls.FindParent <StackPanel>(AutoFilterHelper.CurrentListBox); var popup1 = sp1.Parent as Popup; if (popup1 != null) { var clearButton = FindControls.FindChild <Button>(popup1.Child, "btnClear"); if (clearButton != null) { clearButton.IsEnabled = true; } } AutoFilterHelper.CurrentListBox.UpdateLayout(); AutoFilterHelper.CurrentListBox.Items.Refresh(); return; } var sp = FindControls.FindParent <StackPanel>(AutoFilterHelper.CurrentListBox); var popup = sp.Parent as Popup; if (popup != null) { popup.Tag = "True"; } AutoFilterHelper.CurrentListBox.UpdateLayout(); AutoFilterHelper.CurrentListBox.Items.Refresh(); } finally { _isLoading = false; } }
private void UnChecked(object sender, RoutedEventArgs e) { if (_isLoading) { return; } try { _isLoading = true; var checkbox = (CheckBox)sender; var listBox = FindControls.FindParent <ListBox>(checkbox); AutoFilterHelper.CurrentListBox = listBox; var popup = (Popup)((StackPanel)(listBox.Parent)).Parent; var grid = FindControls.FindParent <ExtendedDataGrid>(popup); CurrentGrid = AutoFilterHelper.CurrentGrid = grid; var value = Convert.ToString(checkbox.Content); if (Convert.ToString(checkbox.Tag) != "(Select All)") { var distictValues = AutoFilterHelper.CurrentListBox.ItemsSource as List <CheckedListItem>; if (distictValues != null) { var countOfFiltersSelected = distictValues.Count(c => c.IsChecked && c.Name != "(Select All)" && c.IsSelectAll != "(Select All)"); if (countOfFiltersSelected == distictValues.Count - 1) { _isLoading = true; distictValues[0].IsChecked = false; AutoFilterHelper.CurrentListBox.UpdateLayout(); AutoFilterHelper.CurrentListBox.Items.Refresh(); } bool isFilterApplicable = !string.IsNullOrEmpty(((DataView)CurrentGrid.ItemsSource).RowFilter) && ((DataView)CurrentGrid.ItemsSource).RowFilter.Contains(CurrentColumn + " IN "); if (!isFilterApplicable) { if (string.IsNullOrEmpty(((DataView)CurrentGrid.ItemsSource).RowFilter)) { var actualValues = ((DataView)CurrentGrid.ItemsSource).Table.Rows.Cast <DataRow>().Select(row => Convert.ToString(row[CurrentColumn])).Where(val => val != value).ToList(); AutoFilterHelper.ApplyFilters(CurrentGrid, CurrentColumn, actualValues); var distictictValues = AutoFilterHelper.CurrentDistictValues; distictictValues[0].IsChecked = false; AutoFilterHelper.CurrentDistictValues = distictictValues; AutoFilterHelper.CurrentListBox.Items.Refresh(); popup.Tag = distictictValues.Count(c => c.IsChecked) == 0 ? "False" : "True"; CurrentGrid.Items.Refresh(); CurrentGrid.UpdateLayout(); return; } else { AutoFilterHelper.CurrentDistictValues[0].IsChecked = countOfFiltersSelected == distictValues.Count - 1; AutoFilterHelper.CurrentListBox.Items.Refresh(); AutoFilterHelper.CurrentListBox.UpdateLayout(); popup.Tag = AutoFilterHelper.CurrentDistictValues.Count(c => c.IsChecked) == 0 ? "False" : "True"; CurrentGrid.Items.Refresh(); CurrentGrid.UpdateLayout(); } } else { AutoFilterHelper.RemoveFilters(CurrentGrid, CurrentColumn, value); var distictictValues = AutoFilterHelper.CurrentDistictValues; popup.Tag = distictictValues.Count(c => c.IsChecked) == 0 ? "False" : "True"; } } } else { _isLoading = true; var distictictValues = AutoFilterHelper.CurrentDistictValues; distictictValues[0].IsChecked = false; foreach (var distictictValue in distictictValues) { if (distictictValue.Name != "(Select All)" && distictictValue.IsSelectAll != "(Select All)") { distictictValue.IsChecked = false; } } AutoFilterHelper.CurrentDistictValues = distictictValues; AutoFilterHelper.RemoveAllFilter(CurrentGrid, CurrentColumn); AutoFilterHelper.CurrentListBox.Items.Refresh(); var countOfFiltersSelected = distictictValues.Count(c => c.IsChecked && c.Name != "(Select All)"); popup.Tag = countOfFiltersSelected == 0?"False":"True"; } AutoFilterHelper.CurrentGrid.Items.Refresh(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { _isLoading = false; } }