thedonedeal 12 Newbie Poster

When I add a NEW row to the datagridview, it for some reason freezes the datagridview. That is, it adds the rows pulled from the database to the grid. But you can't add rows to the datagrid by some a click button event. Nor can you select a row in the datagrid view.

Below is the query and the code used to add the rows.

Dim JudgesQuery As New OleDb.OleDbCommand("SELECT * FROM JudgeList WHERE TournamentID = ?", Oleconnection)

            JudgesQuery.Parameters.AddWithValue("?", Me.TournID)

            Dim JudgesDataAdapter As New OleDb.OleDbDataAdapter
            Dim JudgesDataTable As New DataTable

            JudgesDataAdapter.SelectCommand = JudgesQuery

            Dim JudgesDataSet As New DataSet
            JudgesDataAdapter.Fill(JudgesDataSet, "Tournaments")
            JudgesDataAdapter.Fill(JudgesDataTable)

            Dim AddJudge As Object()
            Dim Rank As String

            For Judgecounter = 1 To JudgesDataTable.Rows.Count()
                If JudgesDataSet.Tables(0).Rows(Judgecounter - 1).Item("Position") = 0 Then
                    Rank = "HJ"
                Else
                    Rank = "J"
                End If
                AddJudge = {JudgesDataSet.Tables(0).Rows(Judgecounter - 1).Item("Position").ToString, Rank, JudgesDataSet.Tables(0).Rows(Judgecounter - 1).Item("JudgePlayerID").ToString(), JudgeNameLbl.Text}
                JudgeList.Rows.Add(AddJudge)
            Next
Private Sub AddJudgeBtn_Click(sender As System.Object, e As System.EventArgs) Handles AddJudgeBtn.Click
        If JudgeIDTxt.Text <> "" Then

            Dim exists As Boolean

            ' ToDo: If the value entered is already on the list, don't add again.
            If JudgeList.Rows.Count() > 0 Then
                For Each itm As DataGridViewRow In JudgeList.Rows
                    If itm.Cells("JudgeIDNumber").Value = JudgeIDTxt.Text Then
                        exists = True
                    End If
                Next
            End If

            If exists = False Then
                Dim AddJudge As Object()
                Try
                    If JudgeList.Rows.Count = 0 Then
                        ' There are no judges, by default. These person becomes the head judge.
                        AddJudge = {0, "HJ", JudgeIDTxt.Text, JudgeNameLbl.Text}
                        JudgeList.Rows.Add(AddJudge)
                    Else
                        ' There is already a judge/head judge, this person becomes a regular judge.
                        AddJudge = {2, "J", JudgeIDTxt.Text, JudgeNameLbl.Text}
                        JudgeList.Rows.Add(AddJudge)
                    End If

                Catch ex As Exception
                    ' Do Nothing
                End Try
            End If
            JudgeIDTxt.Clear()
            'JudgeIDTxt.Focus() ' Give the field focus back, in case the user wants to add more.
        End If
    End Sub

I'd appreciate any advice or corrections.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.