对于通过DataGridViewColumn标题的每个循环 [英] For Each Loop through DataGridViewColumn Headers
问题描述
我有一个 DataGridView
,名为 DataGridViewHistorical
,它有2012至1900年的列。列标题并使用年份来查找字符串中的特定日期。所以在下面的例子中,我会寻找 2012-01-03,2011-01-03,2010-01-03 ... 1900-01-03。
I have a DataGridView
called DataGridViewHistorical
that has columns for 2012 to 1900. I am trying to loop through the column headers and use the year to find a specific date in a string. So in the example below I would be looking for 2012-01-03, 2011-01-03, 2010-01-03 ... 1900-01-03.
For Each columnYear As DataGridViewColumn In DataGridViewHistorical.Columns
MessageBox.Show(strBuffer.IndexOf(columnYear & "-01-03"))
Next
当我运行这段代码时, &'没有为类型'System.Windows.Forms.DataGridViewColumn'和'String'定义。
When I run this code I get error "Operator '&' is not defined for types 'System.Windows.Forms.DataGridViewColumn' and 'String'."
我怎么能得到这个工作?
How can I get this to work?
推荐答案
我想你正在寻找 HeaderText
DataGridViewColumn
的属性:
I think you are looking for the HeaderText
property of the DataGridViewColumn
:
MessageBox.Show(strBuffer.IndexOf(columnYear.HeaderText & "-01-03"))
这篇关于对于通过DataGridViewColumn标题的每个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!