简体   繁体   中英

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. I'm using .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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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