다음을 통해 공유


DataGridViewRowEventHandler 대리자

정의

DataGridView의 행 관련 이벤트를 처리할 메서드를 나타냅니다.

public delegate void DataGridViewRowEventHandler(System::Object ^ sender, DataGridViewRowEventArgs ^ e);
public delegate void DataGridViewRowEventHandler(object sender, DataGridViewRowEventArgs e);
public delegate void DataGridViewRowEventHandler(object? sender, DataGridViewRowEventArgs e);
type DataGridViewRowEventHandler = delegate of obj * DataGridViewRowEventArgs -> unit
Public Delegate Sub DataGridViewRowEventHandler(sender As Object, e As DataGridViewRowEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.

e
DataGridViewRowEventArgs

이벤트 데이터를 포함하는 DataGridViewRowEventArgs입니다.

예제

다음 예제에서는 코드를 DataGridViewRowEventHandler 처리 하는 대리자를 NewRowNeeded 이벤트입니다. 이 코드 예제는에 제공 된 큰 예제의 일부는 VirtualMode 속성 참조 항목입니다.

    void VirtualConnector::dataGridView1_NewRowNeeded
        (Object^ sender, DataGridViewRowEventArgs^ e)
    {
        newRowNeeded = true;
    }

    void VirtualConnector::dataGridView1_RowsAdded
        (Object^ sender, DataGridViewRowsAddedEventArgs^ e)
    {
        if (newRowNeeded)
        {
            newRowNeeded = false;
            numberOfRows = numberOfRows + 1;
        }
    }

#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
bool newRowNeeded;
private void dataGridView1_NewRowNeeded(object sender,
    DataGridViewRowEventArgs e)
{
    newRowNeeded = true;
}

const int initialSize = 5000000;
int numberOfRows = initialSize;

private void dataGridView1_RowsAdded(object sender,
     DataGridViewRowsAddedEventArgs e)
{
    if (newRowNeeded)
    {
        newRowNeeded = false;
        numberOfRows = numberOfRows + 1;
    }
}

#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>();
    Dim newRowNeeded As Boolean

    Private Sub dataGridView1_NewRowNeeded(ByVal sender As Object, _
        ByVal e As DataGridViewRowEventArgs) _
        Handles dataGridView1.NewRowNeeded

        newRowNeeded = True
    End Sub

    Const initialSize As Integer = 5000000
    Dim numberOfRows As Integer = initialSize

    Private Sub dataGridView1_RowsAdded(ByVal sender As Object, _
        ByVal e As DataGridViewRowsAddedEventArgs) _
        Handles dataGridView1.RowsAdded

        If newRowNeeded Then
            newRowNeeded = False
            numberOfRows = numberOfRows + 1
        End If
    End Sub

#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)

설명

합니다 DataGridViewRowEventHandler 다음 처리 DataGridView 이벤트:

DataGridViewRowEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보