轉帖|使用教程|編輯:龔雪|2015-12-29 09:10:55.000|閱讀 1796 次
概述:在C1DataGrid中,如果包含一個DataGridCheckBoxColumn,您就會發現在Column的單元格中CheckBox是灰色的,因此它不能編輯。現在如果想要改變這種樣式,變成可編輯的狀態。那么本文,就將改變不可編輯的checkbox列狀態。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在C1DataGrid中,如果包含一個DataGridCheckBoxColumn,您就會發現在Column的單元格中CheckBox是灰色的,因此它不能編輯。比如如下單元格是不可用的:
這種不可用的狀態是設計,是因為內部的ReadOnlyCheckBox類。現在如果想要改變這種樣式,變成可編輯的狀態。那么本文,就將改變不可編輯的checkbox列狀態。最基本的知識就是使用LoadedCellPresenter事件,然后設置一個CheckBox。代碼片段如下:
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; } }
因此改變后的樣式,就會如下圖所示:
本文的參考示例如下:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網