我已将 a 更改DataGridViewCheckBoxCell
为在 CheckBox 右侧包含一个反映 CheckBox 值的字符串。为 时true
,字符串为“Value1”;当它的false
字符串应该更改为“Value2”。
字符串值只有在DataGridViewCheckBoxCell
失去焦点后才会改变。我希望在 CheckBox 值更改后立即更改字符串值。我怎样才能做到这一点?
作为参考,这是我的个性化DataGridViewCheckBoxCell
课程:
public class MyDGVCheckBoxCell : DataGridViewCheckBoxCell
{
public static string TRUE_VALUE = "Excitada";
public static string FALSE_VALUE = "Monitorada";
public MyDGVCheckBoxCell(bool isExcitada)
{
FalseValue = FALSE_VALUE;
TrueValue = TRUE_VALUE;
Value = isExcitada ? TRUE_VALUE : FALSE_VALUE;
}
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)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
Rectangle contentBounds = this.GetContentBounds(rowIndex);
Point stringLocation = new Point();
stringLocation.Y = cellBounds.Y + 4;
stringLocation.X = cellBounds.X + contentBounds.Right + 1;
graphics.DrawString(this.Value.ToString(), Control.DefaultFont, System.Drawing.Brushes.Black, stringLocation);
}
}