[英]DataGridView add buttons and text to Header Row
I have a datagridview
that I populate from a loop. 我有一个从循环填充的datagridview
。 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. 我得到包含文本的标题行。
How do I add buttons and text to the header row of datagridview1 instead of just text? 如何将按钮和文本添加到datagridview1的标题行中,而不只是文本?
I am using winforms
and .net 4.5
. 我正在使用winforms
和.net 4.5
。 (I guess I could switch to 4.5.1 if it makes things easier). (我想我可以将它简化为4.5.1)。
As far as I know this is not possible. 据我所知这是不可能的。 Here are ways you could get close: 您可以通过以下方式接近:
Frozen
property and put the buttons in the first row. 设置第一行的“ Frozen
属性 ,并将按钮置于第一行。 May thats helping you 愿您帮忙
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "YourText";
btn.Text = "YourText";
btn.Name = "DGVbutton1";
btn.UseColumnTextForButtonValue = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.