DataGridView中添加按钮和文本标题行 [英] DataGridView add buttons and text to Header Row

查看:584
本文介绍了DataGridView中添加按钮和文本标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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;

这篇关于DataGridView中添加按钮和文本标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆