DataGridViewCellValidatingEventArgs.FormattedValue プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
検証する必要のあるセルの書式指定済みの内容を取得します。
public:
property System::Object ^ FormattedValue { System::Object ^ get(); };
public object FormattedValue { get; }
public object? FormattedValue { get; }
member this.FormattedValue : obj
Public ReadOnly Property FormattedValue As Object
プロパティ値
書式指定済みの値への参照。
例
次のコード例では、 イベントを CellValidating 処理して、正の整数のみがユーザーによって入力されるようにします。 この例は、リファレンス トピックで使用できるより大きな例の VirtualMode 一部です。
void VirtualConnector::dataGridView1_CellValidating
(Object^ sender, DataGridViewCellValidatingEventArgs^ e)
{
int newInteger;
// Don't try to validate the 'new row' until finished
// editing since there
// is not any point in validating its initial value.
if (dataGridView1->Rows[e->RowIndex]->IsNewRow)
{
return;
}
if (!Int32::TryParse(e->FormattedValue->ToString(),
newInteger) || (newInteger < 0))
{
e->Cancel = true;
}
}
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
int newInteger;
// Don't try to validate the 'new row' until finished
// editing since there
// is not any point in validating its initial value.
if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
if (!int.TryParse(e.FormattedValue.ToString(),
out newInteger) || newInteger < 0)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
}
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
ByVal e _
As DataGridViewCellValidatingEventArgs) _
Handles dataGridView1.CellValidating
Me.dataGridView1.Rows(e.RowIndex).ErrorText = ""
Dim newInteger As Integer
' Don't try to validate the 'new row' until finished
' editing since there
' is not any point in validating its initial value.
If dataGridView1.Rows(e.RowIndex).IsNewRow Then Return
If Not Integer.TryParse(e.FormattedValue.ToString(), newInteger) _
OrElse newInteger < 0 Then
e.Cancel = True
Me.dataGridView1.Rows(e.RowIndex).ErrorText = "the value must be a non-negative integer"
End If
End Sub
注釈
ユーザー インターフェイス (UI) を介してユーザーが入力したテキストがプロパティ値になります FormattedValue 。 これは、セル Value プロパティ値に解析される前に検証できる値です。
適用対象
こちらもご覧ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET