简体   繁体   English

检索DataGridView控件的标题行

[英]Retrieve Header row for DataGridView control

I am writing a class to print the contents of a DataGridView, however I'm having trouble extracting the names of the header row. 我正在编写一个类来打印DataGridView的内容,但是我在提取标题行的名称时遇到了麻烦。 I'm using .NET 3.0. 我正在使用.NET 3.0。

Is there an easy way of doing this? 有一个简单的方法吗?
I have seen some methods whereby the controls collections are used, Eg 我已经看到一些使用控件集合的方法,例如

columnTitle = myDataGrid.Controls[0].Controls[0].Text;

however I've yet to get this to work either. 但是我还没有使它工作。

To extract the table contents I use: 要提取表内容,我使用:

cellText = m_dataGrid[row.Index, col.Index].Value.ToString();

Is there not a similar way of accessing the column names...? 有没有类似的方法来访问列名...?

dataGridView.Columns[0].Name should give you the column name for column 0. dataGridView.Columns [0] .Name应该为列0提供列名。

foreach(DataGridViewColumn col in dataGridView.Columns)
 Console.Out.WriteLine(col.Name);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM