Link to home
Create AccountLog in
Avatar of CraigBroadman
CraigBroadman

asked on

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You can get the column names from the DataTable:

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

Bob
Avatar of CraigBroadman
CraigBroadman

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer