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
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
ASKER
I am not actually used a datatable - I am using a data adapter and a dataset.... see below.....
Try
daReport = New SqlClient.SqlDataAdapter(S QLStatemen t, SQLConn)
Catch SQLEx As Exception
MsgBox(SQLEx.Message)
SQLConn.Close()
End Try
Try
objReportDataSet.Clear()
SQLConn.Open()
daReport.Fill(objReportDat aSet, "ReportData")
dgData.DataSource = objReportDataSet.Tables("R eportData" )
SQLConn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
daReport = New SqlClient.SqlDataAdapter(S
Catch SQLEx As Exception
MsgBox(SQLEx.Message)
SQLConn.Close()
End Try
Try
objReportDataSet.Clear()
SQLConn.Open()
daReport.Fill(objReportDat
dgData.DataSource = objReportDataSet.Tables("R
SQLConn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Dim columnName As String = table.Columns(lngCol).Colu
Bob