Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

DataGridView not recognizing Dataset?

I have a function that returns a single row from a SQL Server Database. I'm getting the following error message: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" on the line marked "Error occurs here". That tells me that even though the dataset contains a valid record, for some reason it's not being assigned to the DataGridView. What's up with that? See attached image.


    Private Function GetDetailRecords(ByVal iEquipmentID As Integer)
        Try
            clsDE = New CalTableClasses.CalibrationClasses.DETAILS_Equipment

            InitializeErrorClass(EH)
            BL.GetDetailsEquipmentRecord(iEquipmentID, clsDE, EH)

            If EH.Success Then
                dgvComponents.DataSource = Nothing

                If EH.ErrorMessage = "" Then
                    If EH.DataSet.Tables(0).Rows.Count > 0 Then
                        dgvComponents.DataSource = EH.DataSet.Tables(0)
                        dgvComponents.Columns(18).Visible = False     'Error occurs here
                        dgvComponents.Columns(19).Visible = False
                        dgvComponents.Columns(20).Visible = False
                        dgvComponents.Columns(21).Visible = False
                        dgvComponents.Columns(22).Visible = False
                        dgvComponents.Columns(23).Visible = False
                        dgvComponents.Columns(24).Visible = False
                        dgvComponents.Columns(25).Visible = False

                        For Each row As DataRow In EH.DataSet.Tables(0).Rows
                            If Not IsDBNull(row(1)) Then
                                iSeqNO = row(1)
                            End If
                        Next
                    End If
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "GetDetailRecords() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        Return EH
    End Function

Open in new window

Screenshot.jpg
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlakeMcKenna

ASKER

Shaun,

You just sparked a thought. The grid is empty (no columns/rows). I forgot to set the "AutoGenerateColumns" property. I inserted that statement and it worked as it should!

Thanks!