Modify CheckBox Column Appearance in C1DataGrid

In C1Datagrid for Silverlight, if you include a DataGridCheckBoxColumn, you would notice that CheckBoxes inside the Column cells are grayed out in non-editable state. They appear as if the cells have been disabled. This disabled appearance is a design specification and is implemented by internal C1.Silverlight.DataGrid.ReadOnlyCheckBox Class. Now some of you may like to alter this appearance and give it a more vibrant look similar to what it has in editable state. In this blog implementation, I am providing a small workaround for changing disabled effect on the CheckBox column when they are in non editing state. Basic concept behind this blog implementation is to replace the existing C1.Silverlight.DataGrid.ReadOnlyCheckBox with a regular Checkbox in the LoadedCellPresenter event. Lets see the code snippet for the same.

void c1DataGrid1_LoadedCellPresenter(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e)  
     if (e.Cell.Column.GetType() == typeof(C1.Silverlight.DataGrid.DataGridCheckBoxColumn))  
        CheckBox newCheckBox = new CheckBox();  
        System.Windows.Data.Binding bnd = new System.Windows.Data.Binding();  
        bnd.Source = e.Cell;  
        bnd.Path = new PropertyPath("Value");  
        bnd.Mode = System.Windows.Data.BindingMode.TwoWay;  
        newCheckBox.SetBinding(CheckBox.IsCheckedProperty, bnd);  
        e.Cell.Presenter.Content = newCheckBox;  
        e.Cell.Presenter.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;  
        e.Cell.Presenter.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;  

So the final appearance after the above implementation comes up as below. Download the samples for complete implementation. Download VB Sample Download C# Sample


GrapeCity Developer Tools
comments powered by Disqus