datagridview替换列标题 [英] datagridview replace column header
本文介绍了datagridview替换列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想遍历datagridview控件的每一列.
如果标题包含单词"hello",即"you hello",则将其替换为新单词,例如"great"
这就是我所拥有的,但不确定如何替换
Hi,
I would like to loop through each column of a datagridview control.
If the header contains the word "hello" i.e. "you hello", then it is to be replaced with a new word such as "great"
This is what I have but not sure how to replace
foreach (DataGridViewColumn col in dgv.Columns)
{
string strColumn = col.HeaderText.ToString();
if (strColumn.ToLower().Contains("hello"))
{
//col.HeaderCell.Value = ""
有什么建议吗?
谢谢
Any suggestions please?
Thanks
推荐答案
属性System.Windows.Forms.DataGridViewColumn.HeaderText
具有类型string
,因此代码中的HeaderText.ToString()
是毫无意义的.
同样,该属性是可读写的.这使整个问题变得毫无意义.您可以为其分配字符串值,而不仅仅是读取. 这是您想要的解决方案.
请参阅: http://msdn.microsoft.com/en-us /library/system.windows.forms.datagridviewcolumn.headertext.aspx [
The propertySystem.Windows.Forms.DataGridViewColumn.HeaderText
has the typestring
, soHeaderText.ToString()
in your code is pointless.
Also, this property is read-write; and it makes the whole question pointless. You can assign a string value to it, not just read. This is the solution you wanted.
Please see: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.headertext.aspx[^].
Finally, think at my comment to the question: why? This is a rhetorical question; just think about it. :-)
—SA
尝试:
foreach (DataGridViewColumn col in dgv.Columns)
{
col.HeaderText = col.HeaderText.Replace("hello", "great");
}
headercell.value必须解决.
谢谢
headercell.value is required to solve this.
Thank you
这篇关于datagridview替换列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文