Solved

Why DataGridView records blank?

Posted on 2011-02-25
15
679 Views
Last Modified: 2012-05-11
I have created a vb.net 2010 windows application that has a form.  On the form are two DataGridViews.  The first DGV is bound and loads correctly.  The second DGV is unbound.  This second DGV is loaded when the users clicks on a row in the first DGV.  Clicking a row in the first DGV calls the loading of the second DGV which loads the second DGV using a SQL stored procedure and a parameter from the first DGV click.

The second DGV does retrieve the correct "number" of SQL records and does load the records into the DGV.  However, the second DGV records are blank.  Why is that?

Attached is a screen shot of the form showing the two DGVs.  The first DGV is on the left side and works correctly.  The second DGV is on the right and does load the correct "number" of rows, but the rows for some reason are blank.  They are not blank in the SQL table.

Also attached are two short code listings.  The first shows the procedure that "defines" the second DGV.  This procedure is called during the form load event. The second code listing shows the "loading" of the second DGV using the stored procedure and the parameter.

The stored procedure and it's parameter can be successfully executed in SQL.  When I run the sp, it does return the records with their values.

Thank you for the help.
This listing shows the "defining" of the second DGV and is called from the form load event:

    Private Sub srSet_dgvEvent_Classifications_GridColumns()
        Dim intColID As Integer

        With dgvEvent_Classifications
            intColID = .Columns.Add("mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Master_Event_mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Sort_Order_Class", "Sort Order")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Gender", "Gender")
            .Columns(intColID).Width = 50
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Classification", "Classification")
            .Columns(intColID).Width = 75
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Low", "Low")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("High", "High")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("", "")
            .Columns(intColID).Width = 20
            .Columns(intColID).Visible = True
        End With
    End Sub

=====================================================================================

This listing shows the "loading" of the second DGV using the stored procedure and a parameter and is called in the first DGV's click event:

    Private Sub srLoad_dgvEvent_Classifications2()
        Me.Cursor = Cursors.WaitCursor

        Using connection As New SqlConnection(My.Settings.SqlConnection),
            command As New SqlCommand("Get_All_Master_Event_Classifications_One_Event", connection),
            adapter As New SqlDataAdapter(command)
            command.CommandType = CommandType.StoredProcedure

            'Add parameters, e.g.
            command.Parameters.AddWithValue("@Master_Event_mKey", mEvent_mKey)

            Dim table As New DataTable

            'Get the data
            adapter.Fill(table)

            'Display the data
            Me.dgvEvent_Classifications.DataSource = table
        End Using

        mEvent_Classification_mKey = ""
        Me.Cursor = Cursors.Default
    End Sub

Open in new window

Form-Image.JPG
0
Comment
Question by:EYoung
  • 10
  • 5
15 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 34982997
why don't you declare the dataTable (table) publicly and simply clear it and reload it in srLoad_dgvEvent_Classifications2() ?

that way, you can set the datasource to the gridview in a load event and (assuming the SQL retrieves the same data as in the datagridview) then you hould be clear.
PS> Let the data table automatically create the columns in the datagridview as a check of whether it is being populated
0
 
LVL 7

Author Comment

by:EYoung
ID: 34983175
OK, I declared the dataTable(table) public at the top of the code.  The clearing of the DGV rows now works but the records do not show up.

Attached is the revised code.  Can you modify it to show me your suggestions?

Thank you
Private Sub srLoad_dgvEvent_Classifications()
        Me.Cursor = Cursors.WaitCursor

        table.Clear()

        Using connection As New SqlConnection(My.Settings.SqlConnection),
            command As New SqlCommand("Get_All_Master_Event_Classifications_One_Event", connection),
            adapter As New SqlDataAdapter(command)
            command.CommandType = CommandType.StoredProcedure

            'Add parameters, e.g.
            command.Parameters.AddWithValue("@Master_Event_mKey", mEvent_mKey)

            'Get the data
            adapter.Fill(table)

            'Display the data
            Me.dgvEvent_Classifications.DataSource = table
        End Using

        mEvent_Classification_mKey = ""
        Me.Cursor = Cursors.Default
    End Sub

Open in new window

0
 
LVL 7

Author Comment

by:EYoung
ID: 34983237
OK here is something I found based on your suggestion to let the datatable automatically create the columns.  When I did that, the columns and the data appear.  Now I can see the data in the rows.  Why does running the attached code cause the column headers to appear correctly but the data to be missing in the rows?
Private Sub srSet_dgvEvent_Classifications_GridColumns()
        Dim intColID As Integer

        With dgvEvent_Classifications
            intColID = .Columns.Add("mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Master_Event_mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Sort_Order_Class", "Sort Order")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Gender", "Gender")
            .Columns(intColID).Width = 50
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Classification", "Classification")
            .Columns(intColID).Width = 75
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Low", "Low")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("High", "High")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("", "")
            .Columns(intColID).Width = 20
            .Columns(intColID).Visible = True
        End With
    End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 34983328
Naturally, without your set of data and full code I can not make code suggestions. Your code looks well structured, so my guess is that you have overlooked a small detail, thus my stabs at the problem.

1. I take it that you are firing off the populating routine from one of Grid1's onclick events, if not, how are you?

2. I will also assume that, as per my last suggestion, Grid2's datasource is set at design time / on load, if not, where have you set it? (I see you have set the datasource for dgvEvent_Classifications and I assumed this was Grid2)

3. I am also assuming that the table get populated from the above code (else how would you know you have cleared it?), in which case, can you for now bypass / remove srSet_dgvEvent_Classifications_GridColumns()?
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 34983380
Well at least we solved that bit of the data not showing.

I am not sure why the situation you describe happens, but I know it does. The column headers appear because you have defined them in your load routine. Normally, if you have the datatable and grid bound at design time (the drag and drop way), and go on to define the columns et al, your situation does not happen when you populatethe datatable programatically. So to answer that question would be that I would only speculate, but I know it happens.
0
 
LVL 7

Author Comment

by:EYoung
ID: 34983383
1.  Yes you are correct.  The population of grid2 is fired by the onclick event in grid1.

2.  Grid2's datasource is set at design time.  Yes, dgvEvent_Classifications is grid2.

3.  I can remove srSet_dgvEvent_Classifications_GridColumns(), but I need to set the column widths, alignments, column headers for grid2, and not show the first two columns (the keys).  The line that calls this is 13 in the form load event.

Attached is a full listing of my code for this form.

Thank you for the help.
Imports System.Data.SqlClient

Public Class frmEdit_Events_and_Classifications

    Dim mEvent_mKey As String
    Dim mEvent_Classification_mKey As String
    Public table As New DataTable

    Private Sub frmEdit_Events_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        srClear_Events()
        srClear_Classifications()

        srSet_dgvEvent_Classifications_GridColumns()

        txtEvent_Sort_Order.Focus()
    End Sub

    Private Sub srLoad_dgvEvents()
        Me.Cursor = Cursors.WaitCursor
        Me.Master_EventsTableAdapter.Fill(Me.Master_Events_DataSet.Master_Events)
        dgvEvents.ClearSelection()
        mEvent_mKey = ""
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub dgvEvents_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvEvents.Click
        If dgvEvents.RowCount > 0 Then
            mEvent_mKey = Trim(dgvEvents.CurrentRow.Cells(0).Value)
            txtEvent_Sort_Order.Text = dgvEvents.CurrentRow.Cells(1).Value
            txtEvent_Name.Text = Trim(dgvEvents.CurrentRow.Cells(2).Value)

            lblClassifications_for_Event.Text = txtEvent_Name.Text
            srLoad_dgvEvent_Classifications()
            btnEvents_Exit.Focus()
        Else
            txtEvent_Sort_Order.Focus()
        End If
    End Sub

    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Apply.Click
        'Verify the data entry fields
        txtEvent_Sort_Order.Text = Trim(txtEvent_Sort_Order.Text)
        If txtEvent_Sort_Order.Text = "" Then
            MsgBox("No event Sort Order entered", MsgBoxStyle.Information, "Note")
            txtEvent_Sort_Order.Focus()
            Exit Sub
        ElseIf Not IsNumeric(txtEvent_Sort_Order.Text) Then
            MsgBox("Sort Order not numeric.  Must be numeric, i.e. 1, 2, 3...", MsgBoxStyle.Information, "Note")
            txtEvent_Sort_Order.Focus()
            Exit Sub
        End If

        txtEvent_Name.Text = Trim(txtEvent_Name.Text)
        txtEvent_Name.Text = Replace(txtEvent_Name.Text, "'", "''")
        txtEvent_Name.Text = Replace(txtEvent_Name.Text, """", "")
        txtEvent_Name.Text = Trim(Mid(txtEvent_Name.Text, 1, 30))
        If txtEvent_Sort_Order.Text = "" Then
            MsgBox("Event Name missing", MsgBoxStyle.Information, "Note")
            txtEvent_Name.Focus()
            Exit Sub
        End If

        If mEvent_mKey = "" Then
            mWork_String_2 = Trim(mUser_Name) & "-" & FormatDateTime(Now, DateFormat.ShortDate) & "-" & FormatDateTime(Now, DateFormat.LongTime)
            Using connExpress As New SqlConnection(My.Settings.SqlConnection)
                mWork_String_1 = "INSERT INTO Master_Events" _
                    & " (mKey, Sort_Order_Events, Event_Name)" _
                    & " Values ('" & mWork_String_2 & "', " & txtEvent_Sort_Order.Text & ", '" & txtEvent_Name.Text & "')"

                Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                    connExpress.Open()
                    cmdExpress.ExecuteNonQuery()
                    connExpress.Close()
                End Using
            End Using
        Else
            Using connExpress As New SqlConnection(My.Settings.SqlConnection)
                mWork_String_1 = "UPDATE Master_Events SET" _
                    & " Sort_Order_Events = " & txtEvent_Sort_Order.Text & "," _
                    & " Event_Name = '" & txtEvent_Name.Text & "'" _
                    & " WHERE mKey = '" & mEvent_mKey & "'"

                Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                    connExpress.Open()
                    cmdExpress.ExecuteNonQuery()
                    connExpress.Close()
                End Using
            End Using
        End If

        srClear_Events()
        srClear_Classifications()

        txtClassification_Sort_Order.Focus()
    End Sub

    Private Sub btnEvents_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Delete.Click
        If mEvent_mKey = "" Then
            MsgBox("No Event record selected", MsgBoxStyle.Information, "Note")
            dgvEvents.Focus()
            Exit Sub
        End If

        mResponse = MessageBox.Show("ARE YOU SURE you want to PERMANENTLY REMOVE this record and its classifications?)", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If mResponse = 7 Then
            Exit Sub
        End If

        'OK now delete the physical database table record
        Using connExpress As New SqlConnection(My.Settings.SqlConnection)
            mWork_String_1 = "DELETE Master_Events " _
                & " WHERE mKey = '" & mEvent_mKey & "'"

            Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                connExpress.Open()
                cmdExpress.ExecuteNonQuery()
                connExpress.Close()
            End Using
        End Using

        '**************************************************************************************************************
        '  DON'T FORGET TO DELETE ALL CLASSIFICATIONS FOR THIS EVENT RECORD
        '**************************************************************************************************************

        srClear_Events()
        srClear_Classifications()

        btnEvents_Exit.Focus()
    End Sub

    Private Sub btnEvents_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Clear.Click
        srClear_Events()
    End Sub

    Private Sub srClear_Events()
        srLoad_dgvEvents()
        txtEvent_Sort_Order.Text = ""
        txtEvent_Name.Text = ""

        btnEvent_Classifications_Clear.PerformClick()
        btnEvents_Exit.Focus()
    End Sub

    Private Sub srSet_dgvEvent_Classifications_GridColumns()
        Dim intColID As Integer

        With dgvEvent_Classifications
            intColID = .Columns.Add("mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Master_Event_mKey", "")
            .Columns(intColID).Visible = False
            intColID = .Columns.Add("Sort_Order_Class", "Sort Order")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Gender", "Gender")
            .Columns(intColID).Width = 50
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Classification", "Classification")
            .Columns(intColID).Width = 75
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("Low", "Low")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("High", "High")
            .Columns(intColID).Width = 65
            .Columns(intColID).Visible = True
            intColID = .Columns.Add("", "")
            .Columns(intColID).Width = 20
            .Columns(intColID).Visible = True
        End With
    End Sub

    Private Sub srLoad_dgvEvent_Classifications()
        Me.Cursor = Cursors.WaitCursor

        Using connection As New SqlConnection(My.Settings.SqlConnection),
            command As New SqlCommand("Get_All_Master_Event_Classifications_One_Event", connection),
            adapter As New SqlDataAdapter(command)
            command.CommandType = CommandType.StoredProcedure

            'Add parameters, e.g.
            command.Parameters.AddWithValue("@Master_Event_mKey", mEvent_mKey)

            table.Clear()

            'Get the data
            adapter.Fill(table)

            'Display the data
            Me.dgvEvent_Classifications.DataSource = table
        End Using

        mEvent_Classification_mKey = ""
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub btnEvent_Classifications_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvent_Classifications_Clear.Click
        srClear_Classifications()
    End Sub

    Private Sub srClear_Classifications()
        table.Clear()

        lblClassifications_for_Event.Text = ""
        txtClassification_Sort_Order.Text = ""
        radClassification_Men.Checked = False
        radClassification_Women.Checked = False
        radClassification_Both.Checked = False
        txtClassification.Text = ""
        txtClassification_Low.Text = ""
        txtClassification_High.Text = ""

        btnEvents_Exit.Focus()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Exit.Click
        Me.Close()
    End Sub
End Class

Open in new window

0
 
LVL 7

Author Comment

by:EYoung
ID: 34983422
I missed your second and latest post.

I made grid2 unbound as I did not know how to load it using a stored procedure and a parameter.  The parameter is filled in each time grid1 is clicked.  The parm contains the key to the selected record in grid1 and that key is used to selectively retrieve records for grid2.   Anyway, I tried to figure out how to load grid2 using the sp and parm but could not get it to work.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 34983531
I am going to have to get back to you later (even 2moro). I thought we'd made some headway, but seems like I need to cast a more critical eye on your class but need to put the kids to bed (and soon it will be my very own too!)
0
 
LVL 7

Author Comment

by:EYoung
ID: 34983554
OK thank you for your help.  Hope you can return tomorrow.
0
 
LVL 7

Author Comment

by:EYoung
ID: 34984145
When I do not format the second DGV and instead just let the table load and format the grid, I can see the records and the data in each field correctly.

When I do not comment out line 12 of the attached code and thus allow the "srSet_dgvEvent_Classifications_GridColumns()" code to execute, I see the correctly formatted column headers and the correct "number" of rows, but no data is shown in the DGV rows.  Just blank rows are shown.

The stored procedure with the parm works correctly in SQL and when I comment out line 12.

Attached is the full code listing for this form.

Would appreciate any help as I am running up against a tight deadline.

Thank you.
Imports System.Data.SqlClient

Public Class frmEdit_Events_and_Classifications

    Dim mEvent_mKey As String
    Dim mEvent_Classification_mKey As String
    Public table As New DataTable

    Private Sub frmEdit_Events_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        srClear_Events()
        srClear_Classifications()
        srSet_dgvEvent_Classifications_GridColumns()    'When I comment out this line, the data shows up.

        txtEvent_Sort_Order.Focus()
    End Sub

    Private Sub srLoad_dgvEvents()
        Me.Cursor = Cursors.WaitCursor
        Me.Master_EventsTableAdapter.Fill(Me.Master_Events_DataSet.Master_Events)
        dgvEvents.ClearSelection()
        mEvent_mKey = ""
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub dgvEvents_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvEvents.Click
        If dgvEvents.RowCount > 0 Then
            mEvent_mKey = Trim(dgvEvents.CurrentRow.Cells(0).Value)
            txtEvent_Sort_Order.Text = dgvEvents.CurrentRow.Cells(1).Value
            txtEvent_Name.Text = Trim(dgvEvents.CurrentRow.Cells(2).Value)

            lblClassifications_for_Event.Text = txtEvent_Name.Text
            srClear_Classifications()
            srLoad_dgvEvent_Classifications()
            btnEvents_Exit.Focus()
        Else
            txtEvent_Sort_Order.Focus()
        End If
    End Sub

    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Apply.Click
        'Verify the data entry fields
        txtEvent_Sort_Order.Text = Trim(txtEvent_Sort_Order.Text)
        If txtEvent_Sort_Order.Text = "" Then
            MsgBox("No event Sort Order entered", MsgBoxStyle.Information, "Note")
            txtEvent_Sort_Order.Focus()
            Exit Sub
        ElseIf Not IsNumeric(txtEvent_Sort_Order.Text) Then
            MsgBox("Sort Order not numeric.  Must be numeric, i.e. 1, 2, 3...", MsgBoxStyle.Information, "Note")
            txtEvent_Sort_Order.Focus()
            Exit Sub
        End If

        txtEvent_Name.Text = Trim(txtEvent_Name.Text)
        txtEvent_Name.Text = Replace(txtEvent_Name.Text, "'", "''")
        txtEvent_Name.Text = Replace(txtEvent_Name.Text, """", "")
        txtEvent_Name.Text = Trim(Mid(txtEvent_Name.Text, 1, 30))
        If txtEvent_Sort_Order.Text = "" Then
            MsgBox("Event Name missing", MsgBoxStyle.Information, "Note")
            txtEvent_Name.Focus()
            Exit Sub
        End If

        If mEvent_mKey = "" Then
            mWork_String_2 = Trim(mUser_Name) & "-" & FormatDateTime(Now, DateFormat.ShortDate) & "-" & FormatDateTime(Now, DateFormat.LongTime)
            Using connExpress As New SqlConnection(My.Settings.SqlConnection)
                mWork_String_1 = "INSERT INTO Master_Events" _
                    & " (mKey, Sort_Order_Events, Event_Name)" _
                    & " Values ('" & mWork_String_2 & "', " & txtEvent_Sort_Order.Text & ", '" & txtEvent_Name.Text & "')"

                Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                    connExpress.Open()
                    cmdExpress.ExecuteNonQuery()
                    connExpress.Close()
                End Using
            End Using
        Else
            Using connExpress As New SqlConnection(My.Settings.SqlConnection)
                mWork_String_1 = "UPDATE Master_Events SET" _
                    & " Sort_Order_Events = " & txtEvent_Sort_Order.Text & "," _
                    & " Event_Name = '" & txtEvent_Name.Text & "'" _
                    & " WHERE mKey = '" & mEvent_mKey & "'"

                Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                    connExpress.Open()
                    cmdExpress.ExecuteNonQuery()
                    connExpress.Close()
                End Using
            End Using
        End If

        srClear_Events()
        srClear_Classifications()

        txtClassification_Sort_Order.Focus()
    End Sub

    Private Sub btnEvents_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Delete.Click
        If mEvent_mKey = "" Then
            MsgBox("No Event record selected", MsgBoxStyle.Information, "Note")
            dgvEvents.Focus()
            Exit Sub
        End If

        mResponse = MessageBox.Show("ARE YOU SURE you want to PERMANENTLY REMOVE this record and its classifications?)", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If mResponse = 7 Then
            Exit Sub
        End If

        'OK now delete the physical database table record
        Using connExpress As New SqlConnection(My.Settings.SqlConnection)
            mWork_String_1 = "DELETE Master_Events " _
                & " WHERE mKey = '" & mEvent_mKey & "'"

            Using cmdExpress As New SqlCommand(mWork_String_1, connExpress)
                connExpress.Open()
                cmdExpress.ExecuteNonQuery()
                connExpress.Close()
            End Using
        End Using

        '**************************************************************************************************************
        '  DON'T FORGET TO DELETE ALL CLASSIFICATIONS FOR THIS EVENT RECORD
        '**************************************************************************************************************

        srClear_Events()
        srClear_Classifications()

        btnEvents_Exit.Focus()
    End Sub

    Private Sub btnEvents_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Clear.Click
        srClear_Events()
    End Sub

    Private Sub srClear_Events()
        srLoad_dgvEvents()
        txtEvent_Sort_Order.Text = ""
        txtEvent_Name.Text = ""
        lblClassifications_for_Event.Text = ""

        table.Clear()
        srClear_Classifications()
        btnEvents_Exit.Focus()
    End Sub

    Private Sub srSet_dgvEvent_Classifications_GridColumns()
        'Define dgvEvent_Classifications
        dgvEvent_Classifications.ColumnCount = 8

        dgvEvent_Classifications.Columns(0).Name = "mKey"
        dgvEvent_Classifications.Columns(0).HeaderText = ""
        dgvEvent_Classifications.Columns(0).Visible = False
        dgvEvent_Classifications.Columns(0).Width = 0

        dgvEvent_Classifications.Columns(1).HeaderText = ""
        dgvEvent_Classifications.Columns(1).Name = "Master_Event_mKey"
        dgvEvent_Classifications.Columns(1).Visible = False
        dgvEvent_Classifications.Columns(1).Width = 0

        dgvEvent_Classifications.Columns(2).Name = "Sort_Order_Class"
        dgvEvent_Classifications.Columns(2).HeaderText = "Sort Order"
        dgvEvent_Classifications.Columns(2).Visible = True
        dgvEvent_Classifications.Columns(2).Width = 65

        dgvEvent_Classifications.Columns(3).HeaderText = "Gender"
        dgvEvent_Classifications.Columns(3).Name = "Gender"
        dgvEvent_Classifications.Columns(3).Visible = True
        dgvEvent_Classifications.Columns(3).Width = 50

        dgvEvent_Classifications.Columns(4).Name = "Classification"
        dgvEvent_Classifications.Columns(4).HeaderText = "Classification"
        dgvEvent_Classifications.Columns(4).Visible = True
        dgvEvent_Classifications.Columns(4).Width = 75

        dgvEvent_Classifications.Columns(5).HeaderText = "Low"
        dgvEvent_Classifications.Columns(5).Name = "Low"
        dgvEvent_Classifications.Columns(5).Visible = True
        dgvEvent_Classifications.Columns(5).Width = 65

        dgvEvent_Classifications.Columns(6).Name = "High"
        dgvEvent_Classifications.Columns(6).HeaderText = "High"
        dgvEvent_Classifications.Columns(6).Visible = True
        dgvEvent_Classifications.Columns(6).Width = 65

        dgvEvent_Classifications.Columns(7).HeaderText = ""
        dgvEvent_Classifications.Columns(7).Name = ""
        dgvEvent_Classifications.Columns(7).Visible = True
        dgvEvent_Classifications.Columns(7).Width = 50
    End Sub

    Private Sub srLoad_dgvEvent_Classifications()
        Me.Cursor = Cursors.WaitCursor

        Using connection As New SqlConnection(My.Settings.SqlConnection),
            command As New SqlCommand("Get_All_Master_Event_Classifications_One_Event", connection),
            adapter As New SqlDataAdapter(command)
            command.CommandType = CommandType.StoredProcedure

            'Add parameters, e.g.
            command.Parameters.AddWithValue("@Master_Event_mKey", mEvent_mKey)

            table.Clear()

            'Get the data
            adapter.Fill(table)

            'Display the data
            Me.dgvEvent_Classifications.DataSource = table
        End Using

        mEvent_Classification_mKey = ""
        dgvEvent_Classifications.ClearSelection()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub dgvEvent_Classifications_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvEvent_Classifications.Click
        If dgvEvent_Classifications.RowCount > 0 Then
            mEvent_Classification_mKey = Trim(dgvEvent_Classifications.CurrentRow.Cells(0).Value)

            txtClassification_Sort_Order.Text = dgvEvent_Classifications.CurrentRow.Cells(2).Value

            If dgvEvent_Classifications.CurrentRow.Cells(3).Value = "M" Then
                radClassification_Men.Checked = True
            ElseIf dgvEvent_Classifications.CurrentRow.Cells(3).Value = "W" Then
                radClassification_Women.Checked = True
            ElseIf dgvEvent_Classifications.CurrentRow.Cells(3).Value = "B" Then
                radClassification_Both.Checked = True
            Else
                radClassification_Men.Checked = False
                radClassification_Women.Checked = False
                radClassification_Both.Checked = False
            End If

            txtClassification.Text = Trim(dgvEvent_Classifications.CurrentRow.Cells(4).Value)
            txtClassification_Low.Text = Trim(dgvEvent_Classifications.CurrentRow.Cells(5).Value)
            txtClassification_High.Text = Trim(dgvEvent_Classifications.CurrentRow.Cells(6).Value)

            btnEvents_Exit.Focus()
        Else
            mEvent_Classification_mKey = ""
            txtEvent_Sort_Order.Focus()
        End If
    End Sub

    Private Sub btnEvent_Classifications_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvent_Classifications_Clear.Click
        srClear_Classifications()
    End Sub

    Private Sub srClear_Classifications()
        mEvent_Classification_mKey = ""

        txtClassification_Sort_Order.Text = ""
        radClassification_Men.Checked = False
        radClassification_Women.Checked = False
        radClassification_Both.Checked = False
        txtClassification.Text = ""
        txtClassification_Low.Text = ""
        txtClassification_High.Text = ""

        dgvEvent_Classifications.Focus()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvents_Exit.Click
        Me.Close()
    End Sub
End Class

Open in new window

0
 
LVL 7

Author Comment

by:EYoung
ID: 34984181
Can someone help me with this problem?  Thank you.
0
 
LVL 7

Author Comment

by:EYoung
ID: 34984311
I resolved this problem by adding this line just after loading the grid:
srSet_dgvEvent_Classifications_GridColumns()

Now it reads:

    Private Sub srLoad_dgvEvent_Classifications()
        Me.Cursor = Cursors.WaitCursor

        Using connection As New SqlConnection(My.Settings.SqlConnection),
            command As New SqlCommand("Get_All_Master_Event_Classifications_One_Event", connection),
            adapter As New SqlDataAdapter(command)
            command.CommandType = CommandType.StoredProcedure

            'Add parameters, e.g.
            command.Parameters.AddWithValue("@Master_Event_mKey", mEvent_mKey)

            table.Clear()

            'Get the data
            adapter.Fill(table)

            'Load and format the grid
            dgvEvent_Classifications.DataSource = table
            srSet_dgvEvent_Classifications_GridColumns()
        End Using

        mEvent_Classification_mKey = ""
        dgvEvent_Classifications.ClearSelection()
        Me.Cursor = Cursors.Default
    End Sub
0
 
LVL 7

Author Closing Comment

by:EYoung
ID: 34984323
See my last comment and thank you for the help.  You solved parts of the problem and guided me towards solving the remaining parts.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 34986139
Ah! I see you managed to resolve this then. It had to be something simple as your code seemed well structured (albeit for the misplaced line of code you mention).
0
 
LVL 7

Author Comment

by:EYoung
ID: 34987710
Yes, it is working well now.  I just do not understand enough about how the bound and unbound controls work.  Thank you again for your help and guidance and for checking back in..

It was nice to read that you had to put your children to bed.  When my children were younger, I use to do that.  Now I occassionally do that with my grandchilldren now which is really nice.

Best to you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now