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

asked on

Error adding a row to a DataGridView?

I don't know why I have so much trouble with DGV's but here's another one. I keep getting the following error (see attached image) on the line of code indicated.

    Private Sub LoadTestGrid()
        Try
            Dim col As DataGridViewColumn
            Dim cell As DataGridViewTextBoxCell

            With dgvEquip
                col = New DataGridViewColumn
                cell = New DataGridViewTextBoxCell
                col.CellTemplate = cell
                col.Width = 60
                col.HeaderText = "Unit"
                .Columns.Add(col)

                col = New DataGridViewColumn
                cell = New DataGridViewTextBoxCell
                col.CellTemplate = cell
                col.Width = 80
                col.HeaderText = "Output (" & cmbVoltage.SelectedText & ")"
                .Columns.Add(col)

                col = New DataGridViewColumn
                cell = New DataGridViewTextBoxCell
                col.CellTemplate = cell
                col.Width = 80
                col.HeaderText = "Pass/Fail"
                .Columns.Add(col)
            End With

            Dim row As DataGridViewRow

            row = New DataGridViewRow
            dgvEquip.Rows.Add(row)
            row.Cells(0).Value = 20
            row.Cells(1).Value = String.Empty
            row.Cells(2).Value = String.Empty

            row = New DataGridViewRow
            dgvEquip.Rows.Add(row)
            row.Cells(0).Value = 30       <====== Receive Error Message Here
            row.Cells(1).Value = String.Empty
            row.Cells(2).Value = String.Empty

            dgvEquip.CurrentCell = dgvEquip(1, 1)
            dgvEquip.Focus()

        Catch ex As Exception
            EH.ErrorMessage = "LoadTestGrid() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

Screenshot.jpg
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
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

Sorry, forgot about this question. Your solution worked Fernando!
Not a problem BlakeMcKenna, glad to help.