| private void Window_Loaded(object sender, RoutedEventArgs e) { grid.AllowSelection = GridSelectionFlags.Table | GridSelectionFlags.Row | GridSelectionFlags.Column | GridSelectionFlags.Cell; grid.CopyPasteOption = CopyPaste.CopyText | CopyPaste.PasteText; this.grid.Model.QueryCellInfo += Model_QueryCellInfo; } private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { try { UpdateCellBackground(e.Cell, e.Style); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private void UpdateCellBackground(RowColumnIndex rowColumnIndex, GridStyleInfo style) { int rowIndex = rowColumnIndex.RowIndex; if (rowIndex >= 2) { var item = grid.Model.View.Records[rowIndex - 2]; if(item != null) { var zipCodes = item.Data as ZipCodeInfo; if(zipCodes.City.Equals("MAYAGUEZ")) { style.Background = Brushes.Aqua; } } } } |
| <syncfusion:GridDataControl.ConditionalFormats> <syncfusion:GridDataConditionalFormat Name="C1"> <syncfusion:GridDataConditionalFormat.Style> <syncfusion:GridDataStyleInfo Background="Aqua" /> </syncfusion:GridDataConditionalFormat.Style> <syncfusion:GridDataConditionalFormat.Conditions> <syncfusion:GridDataCondition ColumnName="City" Value="MAYAGUEZ" /> </syncfusion:GridDataConditionalFormat.Conditions> </syncfusion:GridDataConditionalFormat> </syncfusion:GridDataControl.ConditionalFormats> |
| private void SetConditionalFormats(CheckBox checkbox) { if (checkbox != null) { if (checkbox.IsChecked == true) { GridDataCondition condition = new GridDataCondition() { ColumnName = "City", Value = "MAYAGUEZ" }; var conditionalFormat = new GridDataConditionalFormat() { Conditions = new FreezableCollection<GridDataCondition>(), Style = new GridDataStyleInfo { Background = Brushes.Aqua } }; conditionalFormat.Conditions.Add(condition); this.grid.ConditionalFormats.Add(conditionalFormat); this.grid.Model.View.Refresh(); } else { if (this.grid.ConditionalFormats != null && this.grid.ConditionalFormats.Count > 0) { this.grid.ConditionalFormats.Clear(); this.grid.Model.View.Refresh(); } } } } private void checkBox_Click(object sender, RoutedEventArgs e) { var checkbox = sender as CheckBox; SetConditionalFormats(checkBox); } |