Button nie reaguje przy niciśnięciu w drugiej formatce - WinFroms

0

Witam,

Mam taki problem. Robię prosty dziennik w c# winfroms. Na razie składa się z 2 formsów. O ile przycisk na pierwszej formie (start.cs) działa ok, to już w drugiej (mainTeacher.cs) w ogóle nic się nie dzieje (przycisk btnOK). Sprawdzałem pod debugurem, w ogóle nie wchodzi do metody.

start.cs

namespace ww
{
    public partial class start : Form
    {

        public string password = "";

        public start()
        {
            InitializeComponent();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {

            password = txtPass.Text;
            var db = new SCHOOL2Entities();
            var query = db.Teachers.FirstOrDefault(x => x.Password == password);

            if (query == null)
            {

                lblError.Visible = true;
                lblError.Text = "Logowanie nieudane";

            }

            else  
                
            {

                Teachers obj = new Teachers();
                obj = db.Teachers.FirstOrDefault(x => x.Password == password);
                mainTeacher form = new mainTeacher(obj);
                form.Show();
                
            }


        }
    }
}


 

mainTeacher.cs

 
namespace ww
{
    public partial class mainTeacher : Form
    {
        private Teachers obj;
        private int selectedClass;
    

        public List<Classes> getClassesByTeacher(Teachers obj)
        {
            List<Classes> tab;

            var db = new SCHOOL2Entities();

            var query = from c in db.Classes
                        join tc in db.TeacherClass
                        on c.ClassID equals tc.ClassID
                        where tc.TeacherID == obj.TeacherID
                        select c;

            tab = query.ToList();
            return tab;


        }

        public mainTeacher(Teachers objTeach)
        {

            obj = objTeach;
            InitializeComponent();

        }


        private void mainTeacher_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sCHOOL2DataSet.Classes' table. You can move, or remove it, as needed.
            this.classesTableAdapter.Fill(this.sCHOOL2DataSet.Classes);
            // TODO: This line of code loads data into the 'sCHOOL2DataSet.Students' table. You can move, or remove it, as needed.
            this.studentsTableAdapter.Fill(this.sCHOOL2DataSet.Students);



            lblHello.Text = obj.FirstName + " " + obj.LastName;
            cmbSelectClass.DataSource = getClassesByTeacher(obj);
          
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Dsds");
        }
  
    }
}


Pierwsza forma to po prostu panel logowania, użytkownik wpisuje hasło i otwiera się 2 forma z wyborem klas. Po naciśnięciu przycisku coś będzie się dziać.

1

Czy metoda btnOK_Click jest podpięta pod zdarzenie?

0
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

Czy chodzi o to ?:)

1

Tak, koledze teo215 chodzi o to, wrzuć nam kod tego forma, bo teraz to wróżenie z fusów.

0

a co tam, wrzucam cały projekt:) nie jest duży

0

Ok, jakiś dziwny problem był. Zrobiłem nową formę, skopiowałem kod i teraz się otwiera

1 użytkowników online, w tym zalogowanych: 0, gości: 1