0

データグリッドビューの特定の列の行の最大長を設定する方法は知っていますが、短い長さの文字列を入力すると毎回変更されます.最大長が最初に一度だけ設定されるように長さを設定したいです.文字列の長さ。

たとえば、最初の文字列の長さが 5 の場合、文字列のテキストを変更して長さを 3 に変更しても、最大長は 5 のままです。

これは私のコードです。

    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        //check if currently selected cell is cell you want
        if (dataGridView1.CurrentCell == null || dataGridView1.CurrentCell.ColumnIndex != 2)
        {
            return;
        }

        if (e.Control is TextBox && !(Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[8].Value.ToString())))
        {
            ((TextBox)e.Control).MaxLength = Convert.ToInt16(this.dataGridView1.CurrentRow.Cells[3].Value.ToString());
        }
    }
4

2 に答える 2