DataGridView中添加按钮和文本标题行按钮、文本、标题、DataGridView

2023-09-04 05:47:42 作者:吥怼

我有一个 datagridview的,我从一个循环填充。 如果我做了以下内容:

I have a datagridview that I populate from a loop. If I do the following:

public Form(Dictionary<String, String> headers)
{
    InitializeComponent();
    foreach (var key in headers.Keys) {
        datagridview1.Columns.Add(key, key);
    }
}

我得到一个包含标题行文字。

I get a header row containing text.

如何添加按钮和文本dataGridView1的标题行,而不是只是文字?

How do I add buttons and text to the header row of datagridview1 instead of just text?

我使用的WinForms .NET 4.5 。 (我想我可以切换到4.5.1,如果它使事情变得更容易)。

I am using winforms and .net 4.5. (I guess I could switch to 4.5.1 if it makes things easier).

推荐答案

五月那帮你

 DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
 dataGridView1.Columns.Add(btn);
 btn.HeaderText = "YourText";
 btn.Text = "YourText";
 btn.Name = "DGVbutton1";
 btn.UseColumnTextForButtonValue = true;