C# WinForm DataGridView DataGridViewButtonColumn列禁用
2021-05-04 21:29
标签:ring GridView bsp str ack string col wpa temp 先添加一下两个类 #region 禁用 DataGridViewButtonColumn public class DataGridViewDisableButtonCell : DataGridViewButtonCell public override object Clone() public DataGridViewDisableButtonCell() protected override void Paint(Graphics graphics, if ((paintParts & DataGridViewPaintParts.Border) == if (this.FormattedValue is String) 若DataGridView 已绑定数据使用以下方法 private void DisableButtonCell(DataGridView dgv,string strKey) } C# WinForm DataGridView DataGridViewButtonColumn列禁用 标签:ring GridView bsp str ack string col wpa temp 原文地址:http://www.cnblogs.com/hefy/p/7698526.html
public class DataGridViewDisableButtonColumn : DataGridViewButtonColumn
{
public DataGridViewDisableButtonColumn()
{
this.CellTemplate = new DataGridViewDisableButtonCell();
}
}
{
private bool enabledValue;
public bool Enabled
{
get
{
return enabledValue;
}
set
{
enabledValue = value;
}
}
{
DataGridViewDisableButtonCell cell =
(DataGridViewDisableButtonCell)base.Clone();
cell.Enabled = this.Enabled;
return cell;
}
{
this.enabledValue = true;
}
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value,
object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (!this.enabledValue)
{
if ((paintParts & DataGridViewPaintParts.Background) ==
DataGridViewPaintParts.Background)
{
SolidBrush cellBackground =
new SolidBrush(cellStyle.BackColor);
graphics.FillRectangle(cellBackground, cellBounds);
cellBackground.Dispose();
}
DataGridViewPaintParts.Border)
{
PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
advancedBorderStyle);
}
Rectangle buttonArea = cellBounds;
Rectangle buttonAdjustment =
this.BorderWidths(advancedBorderStyle);
buttonArea.X += buttonAdjustment.X;
buttonArea.Y += buttonAdjustment.Y;
buttonArea.Height -= buttonAdjustment.Height;
buttonArea.Width -= buttonAdjustment.Width;
ButtonRenderer.DrawButton(graphics, buttonArea,
System.Windows.Forms.VisualStyles.PushButtonState.Disabled);
{
TextRenderer.DrawText(graphics,
(string)this.FormattedValue,
this.DataGridView.Font,
buttonArea, SystemColors.GrayText);
}
}
else
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
elementState, value, formattedValue, errorText,
cellStyle, advancedBorderStyle, paintParts);
}
}
}
#endregion
{
for (int j = 0; j {
if (dgv.Rows[j].Cells[strKey].Value.ToString() == "要禁用的数据值")
{
if (dgv.Rows[j].Cells[strKey] is DataGridViewDisableButtonCell)
((DataGridViewDisableButtonCell)dgv.Rows[j].Cells[strKey]).Enabled = false; //禁用
}
}
下一篇:delphi ribbon使用
文章标题:C# WinForm DataGridView DataGridViewButtonColumn列禁用
文章链接:http://soscw.com/index.php/essay/82438.html