DataGridView.CellValuePushed 이벤트

정의

DataGridView 컨트롤의 VirtualMode 속성이 true이고 변경된 셀 값에 내부 데이터 원본의 스토리지가 필요할 때 발생합니다.

public:
 event System::Windows::Forms::DataGridViewCellValueEventHandler ^ CellValuePushed;
public event System.Windows.Forms.DataGridViewCellValueEventHandler CellValuePushed;
public event System.Windows.Forms.DataGridViewCellValueEventHandler? CellValuePushed;
member this.CellValuePushed : System.Windows.Forms.DataGridViewCellValueEventHandler 
Public Custom Event CellValuePushed As DataGridViewCellValueEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 데이터 저장소 개체에 CellValuePushed 업데이트 및 새 항목을 저장 하는 이벤트를 처리 합니다. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 VirtualMode 참조 항목입니다.

#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
#region "data store maintance"
const int initialValue = -1;

private void 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 = store[e.RowIndex];
    }
    else if (newRowNeeded && e.RowIndex == numberOfRows)
    {
        if (dataGridView1.IsCurrentCellInEditMode)
        {
            e.Value = initialValue;
        }
        else
        {
            // Show a blank value if the cursor is just resting
            // on the last row.
            e.Value = String.Empty;
        }
    }
    else
    {
        e.Value = e.RowIndex;
    }
}

private void dataGridView1_CellValuePushed(object sender,
    DataGridViewCellValueEventArgs e)
{
    store.Add(e.RowIndex, int.Parse(e.Value.ToString()));
}
#endregion

private Dictionary<int, int> store = new Dictionary<int, int>();
#Region "data store maintance"
    Const initialValue As Integer = -1

    Private Sub dataGridView1_CellValueNeeded(ByVal sender As Object, _
        ByVal e As DataGridViewCellValueEventArgs) _
        Handles dataGridView1.CellValueNeeded

        If store.ContainsKey(e.RowIndex) Then
            ' Use the store if the e value has been modified 
            ' and stored.
            e.Value = store(e.RowIndex)
        ElseIf newRowNeeded AndAlso e.RowIndex = numberOfRows Then
            If dataGridView1.IsCurrentCellInEditMode Then
                e.Value = initialValue
            Else
                ' Show a blank value if the cursor is just resting
                ' on the last row.
                e.Value = String.Empty
            End If
        Else
            e.Value = e.RowIndex
        End If
    End Sub

    Private Sub dataGridView1_CellValuePushed(ByVal sender As Object, _
        ByVal e As DataGridViewCellValueEventArgs) _
        Handles dataGridView1.CellValuePushed

        store.Add(e.RowIndex, CInt(e.Value))

    End Sub
#End Region

    Dim store As System.Collections.Generic.Dictionary(Of Integer, Integer) = _
        New Dictionary(Of Integer, Integer)

설명

가상 모드에서 이 이벤트를 사용하여 사용자 지정 데이터 저장소를 사용자 지정 데이터로 업데이트합니다. 컨트롤에 CellValueNeeded 표시할 데이터 저장소에서 값을 검색하는 이벤트를 처리합니다.

가상 모드에 대한 자세한 내용은 Windows Forms DataGridView 컨트롤에서 가상 모드를 참조하세요.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보