Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Getting the information from Column Header in a Datagrid

Posted on 2006-03-27
Medium Priority
Last Modified: 2010-04-23
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???

Question by:CraigBroadman
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 16311418
You can get the column names from the DataTable:

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


Author Comment

ID: 16319013
I am not actually used a datatable - I am using a data adapter and a dataset.... see below.....

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

            daReport.Fill(objReportDataSet, "ReportData")
            dgData.DataSource = objReportDataSet.Tables("ReportData")
        Catch ex As Exception
        End Try
LVL 96

Accepted Solution

Bob Learned earned 400 total points
ID: 16320654
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


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question