Nasıl yapılır: Veri Bağlantılı Windows Forms DataGridView Denetimine Bağlantısız Sütun Ekleme

Denetimde görüntüleyilen veriler normalde bir veri kaynağından gelir, ancak veri kaynağından gelen bir veri DataGridView sütununu görüntülemek istemeyebilirsiniz. Bu tür bir sütun, sınırsız sütun olarak adlandırılan bir sütundur. Sınırsız sütunlar birçok biçime sahip olabilir. Genellikle, bir veri satırı ayrıntılarına erişim sağlamak için kullanılır.

Aşağıdaki kod örneğinde, ana/ayrıntı senaryosu uygulanırken üst tablodaki belirli bir satırla ilgili bir alt tabloyu görüntülemek için Details düğmelerinin ilişkisiz bir sütun oluşturma adımları gösterilir. Düğme tıklamalarına yanıt vermek için alt DataGridView.CellClick tabloyu içeren formu görüntüleyen bir olay işleyicisi ekleyin.

Bu görev için bir destek Visual Studio. Ayrıca bkz. Tasarımcı Kullanarak Windows Forms DataGridView Denetiminde Sütun Ekleme ve Kaldırma.

Örnek

private void CreateUnboundButtonColumn()
{
    // Initialize the button column.
    DataGridViewButtonColumn buttonColumn =
        new DataGridViewButtonColumn();
    buttonColumn.Name = "Details";
    buttonColumn.HeaderText = "Details";
    buttonColumn.Text = "View Details";

    // Use the Text property for the button text for all cells rather
    // than using each cell's value as the text for its own button.
    buttonColumn.UseColumnTextForButtonValue = true;

    // Add the button column to the control.
    dataGridView1.Columns.Insert(0, buttonColumn);
}
Private Sub CreateUnboundButtonColumn()

    ' Initialize the button column.
    Dim buttonColumn As New DataGridViewButtonColumn

    With buttonColumn
        .HeaderText = "Details"
        .Name = "Details"
        .Text = "View Details"

        ' Use the Text property for the button text for all cells rather
        ' than using each cell's value as the text for its own button.
        .UseColumnTextForButtonValue = True
    End With

    ' Add the button column to the control.
    dataGridView1.Columns.Insert(0, buttonColumn)

End Sub

Kod Derleniyor

Bu örnek şunları gerektirir:

Ayrıca bkz.