2

DataGridViewCheckBoxCellCheckBox の値を反映する CheckBox の右側の文字列を含むように a を変更しました。の場合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);
    }
}
4

2 に答える 2

1

通常、チェックされたケースのイベントが見つかります。そのイベントで文字列を変更できます。

イベントの詳しい情報はこちら。

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

于 2012-11-07T13:18:57.413 に答える
0

私はイベントCurrentCellDirtyStateChangedを管理するために使用しますCommitEdit

ここにサンプルがあります:

    void dgv_CurrentCellDirtyStateChanged(object sender, EventArgs e)
    {
        if (dgv.Columns[dgv.CurrentCell.ColumnIndex].GetType() == typeof(DataGridViewCheckBoxColumn))
        {
            if (dgv.Columns[dgv.CurrentCell.ColumnIndex].DataPropertyName.StartsWith("_nodb_"))
            {
                dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }            
    }
于 2016-08-29T08:46:39.407 に答える