Getting the information from Column Header in a Datagrid

I have a datagrid that has been populated from a dataset.

I need to be able to loop though the grid and get the data from it.... i have the following working code....

        For lngRow = 0 To dgData.VisibleRowCount - 1

            For lngCol = 0 To dgData.VisibleColumnCount - 1

                strData = strData & dgData.Item(lngRow, lngCol)
                If lngCol < dgData.VisibleColumnCount - 1 Then strData = strData & vbTab

            Next lngCol
            strData = strData & vbCrLf
        Next lngRow

This loops through each row and each column and adds the data to a string - however it only loops though the datagrid starting with the first record - it does not include the Field Names (columns headings)


can anyone tell me how to get the details of the column headings please???



Thanks
CraigBroadmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You can get the column names from the DataTable:

Dim columnName As String = table.Columns(lngCol).ColumnName

Bob
0
CraigBroadmanAuthor Commented:
I am not actually used a datatable - I am using a data adapter and a dataset.... see below.....


Try
            daReport = New SqlClient.SqlDataAdapter(SQLStatement, SQLConn)
        Catch SQLEx As Exception
            MsgBox(SQLEx.Message)
            SQLConn.Close()
        End Try

        Try
            objReportDataSet.Clear()
            SQLConn.Open()
            daReport.Fill(objReportDataSet, "ReportData")
            dgData.DataSource = objReportDataSet.Tables("ReportData")
            SQLConn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
0
Bob LearnedCommented:
Yes, but a DataSet is made up of multiple DataTables.

Dim table As DataTable = DataSet1.Tables("Table name goes here")
Dim columnName As String = table.Columns(lngCol).ColumnName

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.