gpt4 book ai didi

c# - 如何结束编辑单元格,在单击时更改其内容?

转载 作者:太空宇宙 更新时间:2023-11-03 13:52:37 25 4
gpt4 key购买 nike

我更改了 DataGridViewCheckBoxCell 以在 CheckBox 的右侧包含一个反射(reflect) 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);
}
}

最佳答案

您通常会为选中的案例找到一个事件。您可以修改该事件中的字符串。

这里是关于事件的更多信息。

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/38f26111-671f-457d-a460-fd5e19b16378

关于c# - 如何结束编辑单元格,在单击时更改其内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13270181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com