For Each Loop through DataGridViewColumn Headers

做~自己de王妃 提交于 2019-12-24 03:06:06

问题


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

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?


回答1:


I think you are looking for the HeaderText property of the DataGridViewColumn:

MessageBox.Show(strBuffer.IndexOf(columnYear.HeaderText & "-01-03"))


来源:https://stackoverflow.com/questions/14631357/for-each-loop-through-datagridviewcolumn-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!