DataGridView::CellValuePushed Event

 

Occurs when the VirtualMode property of the DataGridView control is true and a cell value has changed and requires storage in the underlying data source.

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

public:
event DataGridViewCellValueEventHandler^ CellValuePushed {
	void add(DataGridViewCellValueEventHandler^ value);
	void remove(DataGridViewCellValueEventHandler^ value);
}

Use this event in virtual mode to update a custom data store with user-specified data. Handle the CellValueNeeded event to retrieve values from the data store for display in the control.

For more information about virtual mode, see Virtual Mode in the Windows Forms DataGridView Control.

For more information about handling events, see NIB: Consuming Events.

The following code example handles the CellValuePushed event to store updates and new entries in a data store object. This example is part of a larger example available in the VirtualMode reference topic.

#pragma region Data store maintance

    void VirtualConnector::dataGridView1_CellValueNeeded
        (Object^ sender, DataGridViewCellValueEventArgs^ e)
    {
        if (store->ContainsKey(e->RowIndex))
        {
            // Use the store if the e value has been modified 
            // and stored.            
            e->Value = gcnew Int32(store->default[e->RowIndex]); 
        }
        else if (newRowNeeded && e->RowIndex == numberOfRows)
        {
            if (dataGridView1->IsCurrentCellInEditMode)
            {
                e->Value = initialValue;
            }
            else
            {
                // Show a blank e if the cursor is just loitering
                // over(the) last row.
                e->Value = String::Empty;
            }
        }
        else
        {
            e->Value = e->RowIndex;
        }
    }

    void VirtualConnector::dataGridView1_CellValuePushed
        (Object^ sender, DataGridViewCellValueEventArgs^ e)
    {
        String^ value = e->Value->ToString();
        store[e->RowIndex] = Int32::Parse(value, 
            CultureInfo::CurrentCulture);
    }
#pragma endregion

.NET Framework
Available since 2.0
Return to top
Show: