Error: X is not declared. It may be inaccessible due to its protection level.

Hi Experts,

I have struck thess errors:

Error      1      'DataGridView_HighlightOneRowOnly' is not declared. It may be inaccessible due to its protection level.      D:\Dev-Ver6.0\VB.NET\CIRCLY60\VB.NET\frmTrafficSpectrum.vb      32      14      Explorer Prototype
Error      2      'DataGridView_HighlightRowWithCellEqualsString' is not declared. It may be inaccessible due to its protection level.      D:\Dev-Ver6.0\VB.NET\CIRCLY60\VB.NET\frmTrafficSpectrum.vb      35      14      Explorer Prototype

The code is shown below.

DataGridView_HighlightOneRowOnly and DataGridView_HighlightRowWithCellEqualsString are subs that are called from frmTrafficSpectrum and defined in modDataGridView.

Regards,
Leigh

Here is frmTrafficSpectrum.vb:
Imports System.Data.OleDb

Public Class frmTrafficSpectrum
    Dim boolFormLoading As Boolean
    Private Sub frmTrafficSpectrum_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'LOADSDataSet2.TrafficSpectrumComponents' table. You can move, or remove it, as needed.
        Me.TrafficSpectrumComponentsTableAdapter.Fill(Me.LOADSDataSet2.TrafficSpectrumComponents)
        'TODO: This line of code loads data into the 'LOADSDataSet.TrafficSpectrum' table. You can move, or remove it, as needed.
        Me.TrafficSpectrumTableAdapter.Fill(Me.LOADSDataSet.TrafficSpectrum)
        boolFormLoading = True
        'original code from here:
        '
        '   How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls
        '       http://msdn.microsoft.com/en-us/library/c12c1kx4.aspx
        '
        ' D:\Mincad Intranet\software\VB.NET\Sample Code\Database\DataGridView - Master Detail Example from Microsoft
        '' Bind the DataGridView controls to the BindingSource
        '' components and load the data from the database.
        'masterDataGridView.DataSource = masterBindingSource
        'detailsDataGridView.DataSource = detailsBindingSource
        GetData()

        '' Resize the master DataGridView columns to fit the newly loaded data.
        'masterDataGridView.AutoResizeColumns()

        '' Configure the details DataGridView so that its columns automatically
        '' adjust their widths when the data changes.
        'detailsDataGridView.AutoSizeColumnsMode = _
        '    DataGridViewAutoSizeColumnsMode.AllCells

        'Highlight one row only
        Call DataGridView_HighlightOneRowOnly(dgvSpectrum) '20120829

        'highlight row given by SpectrumID (20120814)
        Call DataGridView_HighlightRowWithCellEqualsString(dgvSpectrum, SpectrumID, boolFormLoading) '20120829

    End Sub
    Private Sub GetData()

        'original code from here:
        '
        '   How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls
        '       http://msdn.microsoft.com/en-us/library/c12c1kx4.aspx
        '
        ' D:\Mincad Intranet\software\VB.NET\Sample Code\Database\DataGridView - Master Detail Example from Microsoft



        Try

            Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
            "Data Source=" + strDataPath + _
            "\LOADS.mdb;Persist Security Info=False"
            Dim connection As OleDbConnection = New OleDbConnection(strConn)
            connection.Open()

            ' Create a DataSet.
            Dim data As New DataSet()
            data.Locale = System.Globalization.CultureInfo.InvariantCulture

            ' Add data from the TrafficSpectrum table to the DataSet.
            Dim masterDataAdapter As _
                New OleDbDataAdapter("select * from TrafficSpectrum", connection)
            masterDataAdapter.Fill(data, "TrafficSpectrum")

            ' Add data from the TrafficSpectrumComponents table to the DataSet.
            Dim detailsDataAdapter As _
                New OleDbDataAdapter("select * from TrafficSpectrumComponents", connection)
            detailsDataAdapter.Fill(data, "TrafficSpectrumComponents")

            ' Establish a relationship between the two tables.
            Dim relation As New DataRelation("TrafficSpectrumTrafficSpectrumComponents", _
                data.Tables("TrafficSpectrum").Columns("TrafficSpectrumID"), _
                data.Tables("TrafficSpectrumComponents").Columns("TrafficSpectrumID"))
            data.Relations.Add(relation)

            ' Bind the master data connector to the TrafficSpectrum table.
            TrafficSpectrumBindingSource.DataSource = data
            TrafficSpectrumBindingSource.DataMember = "TrafficSpectrum"

            ' Bind the details data connector to the master data connector,
            ' using the DataRelation name to filter the information in the 
            ' details table based on the current row in the master table. 
            TrafficSpectrumComponentsBindingSource.DataSource = TrafficSpectrumBindingSource
            TrafficSpectrumComponentsBindingSource.DataMember = "TrafficSpectrumTrafficSpectrumComponents"
        Catch ex As OleDb.OleDbException
            MessageBox.Show("To run this example, replace the value of the " & _
                "connectionString variable with a connection string that is " & _
                "valid for your system.")
        End Try

    End Sub


    Private Sub dgvSpectrum_SelectionChanged(sender As Object, e As System.EventArgs) Handles dgvSpectrum.SelectionChanged

        'Capture the ID of the selected row (assumed to be first column)

        'loop through every item in DataGridView
        For Each SelectedRow As DataGridViewRow In dgvSpectrum.SelectedRows()

            If Not boolFormLoading Then
                SpectrumID = SelectedRow.Cells(0).Value.ToString '20120817
            End If
        Next
    End Sub

End Class

Open in new window


Here is modDataGridView.frm:

Public Module modDataGridView
    Public Sub DataGridView_HighlightRowWithCellEqualsString(dgv As DataGridView, strSearch As String, boolFormLoading As Boolean)

        'highlight row given by strSearch (assumes we are searching first column)

        For i As Integer = 0 To dgv.Rows.Count - 1
            If dgv.Item(0, i).Value = strSearch Then
                dgv.CurrentCell = dgv.Item(0, i)
                Exit For
            End If
        Next
        boolFormLoading = False

    End Sub
    Public Sub DataGridView_HighlightOneRowOnly(dgv As DataGridView)

        'Highlight one row only

        With dgv
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
        End With

    End Sub

End Module

Open in new window

LVL 1
LeighWardleAsked:
Who is Participating?
 
mvdeveloperCommented:
Try prefacing the call with the name of the module so it knows where to find it.

modDataGridView.DataGridView_HighlightOneRowOnly(dgvSpectrum)
0
 
LeighWardleAuthor Commented:
Weird - The problem was that my file modDataGridView.frm mistakenly had the extension .frm.

It compiled without error as soon as I changed the extension to  .vb.
0
 
mvdeveloperCommented:
Glad to know you're back on track.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.