views:

298

answers:

1

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, E.g.

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...?

A: 

dataGridView.Columns[0].Name should give you the column name for column 0.

foreach(DataGridViewColumn col in dataGridView.Columns)
 Console.Out.WriteLine(col.Name);
chikak
Nice one. I knew it would be something silly and obvious! Thanks for the quick response.
Kildareflare