is inaccessable due to its protection level

minihu 21 Reputation points
2022-06-03T02:22:57.427+00:00

Good morning, everyone! I am currently working on my first project in Visual Studio and I encountered that problem. May I ask some ideas where did I miss?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_Activity_Tracker
{
    public partial class Form1 : Form
    {
        Form2 form;
        public Form1()
        {
            InitializeComponent();
            form = new Form2(this);
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        public void Display()
        {
            ATStudent.DisplayAndSearch("SELECT ID, Subject, Activity, Dos FROM student_table", dataGridView1);

        }
        private void btnNew_Click(object sender, EventArgs e)
        {
            form.Clear();
            form.ShowDialog();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            Display();
        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            ATStudent.DisplayAndSearch("SELECT ID, Subject, Activity, Dos FROM student_table WHERE Subject LIKE '%"+ txtSearch.Text +"%'", dataGridView1);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.ColumnIndex == 0)
            {
                //edit
                form.Clear();
                form.ID = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                form.Subject = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                form.Activity = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                form.Date = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                form.UpdateInfo();
                form.ShowDialog(); 
                return;
            }
            if(e.ColumnIndex == 2)
            {
                //delete
               if (MessageBox.Show("Do you want to delete the record?", "Information", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    ATStudent.DeleteStudent(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString());
                    Display();
                }
                return;
            }
        }
    }
}
Developer technologies | VB
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2022-06-03T05:34:20.29+00:00

    May I ask some ideas where did I miss?

    You missed to describe the issue you get and/or error message, which we can't guess.

    0 comments No comments

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-06-03T08:54:11.92+00:00

    In short, inaccessable due to its protection level means you are trying to access a control in the other form with it's Modifiers property set to private and to access it you need to change it to public. Similarly if a property or method is setup as private you need to change to public.

    See also Access Modifiers (C# Programming Guide)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.