DataGridViewCellValidatingEventArgs.FormattedValue Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient le contenu mis en forme de la cellule à valider.
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
Valeur de propriété
Référence à la valeur mise en forme.
Exemples
L’exemple de code suivant gère l’événement CellValidating pour garantir que seuls les entiers positifs sont entrés par l’utilisateur. Cet exemple fait partie d’un exemple plus vaste disponible dans la rubrique de VirtualMode référence.
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
Remarques
Le texte entré par l’utilisateur via l’interface utilisateur devient la valeur de propriété FormattedValue . Il s’agit de la valeur que vous pouvez valider avant d’être analysé dans la valeur de la propriété de cellule Value .
S’applique à
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour