询问者
一个问题,关于DataGridViewCell,更改ReadOnly属性的通知的

问题
全部回复
-
我是这样写的:
class MyDataGridViewCheckBoxCell { public override bool ReadOnly { get { if (this.OwningColumn.ReadOnly) return true; return base.ReadOnly; } set { bool columnReadOnly = this.DataGridView.Columns[this.ColumnIndex].ReadOnly; base.ReadOnly = value; this.DataGridView.InvalidateCell(this); if (columnReadOnly == true && value == false) this.DataGridView.InvalidateCell(this.DataGridView.Columns[this.ColumnIndex].HeaderCell); } } protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (this.ReadOnly == false) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.ContentForeground); //Size s = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.CheckedDisabled); //CheckBoxRenderer.DrawCheckBox(graphics, new Point((cellBounds.Width - s.Width) / 2 + cellBounds.X - 1, cellBounds.Y + (cellBounds.Height - s.Height) / 2 - 1) // , (true.Equals(formattedValue) ? CheckBoxState.CheckedDisabled : CheckBoxState.UncheckedDisabled)); if (this.RowIndex >= 0 && true.Equals(this.Value)) graphics.DrawString("√", SystemFonts.DefaultFont, SystemBrushes.WindowText, cellBounds, StringFormatCenter); } } }
QQ:249590012 mail:yyz985@yahoo.com.cn