Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGridViewCellValidatingEventArgs::FormattedValue Property

 

Gets the formatted contents of the cell that needs to be validated.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property Object^ FormattedValue {
	Object^ get();
}

Property Value

Type: System::Object^

A reference to the formatted value.

The text entered by the user through the user interface (UI) becomes the FormattedValue property value. This is the value that you can validate before it is parsed into the cell Value property value.

The following code example handles the CellValidating event to ensure that only positive integers are entered by the user. This example is part of a larger example available in the VirtualMode reference topic.

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;
    }
}

.NET Framework
Available since 2.0
Return to top
Show:
© 2017 Microsoft