private void gvRegisterUser_CellContentClick(object sender, DataGridViewCellEventArgs e) { server.Service1 myserver = new server.Service1(); bool is_found = false; if (e.ColumnIndex == 0) { foreach (server.Subject s in myserver.loggedInStudentSubject()) { if (s == myserver.getSubjects()[e.RowIndex]) { myserver.unregisterSubject(myserver.loggedInStudent(), myserver.getSubjects()[e.RowIndex]); MessageBox.Show("Subject Unregistered"); is_found = true; } } if (!is_found) { myserver.registerSubject(myserver.loggedInStudent(), myserver.getSubjects()[e.RowIndex]); DataGridViewTextBoxCell sc = new DataGridViewTextBoxCell(); sc.Value = "Registered"; gvRegisterSubjects.Rows[e.RowIndex].Cells[0] = sc; MessageBox.Show("You are registered in the subject"); } } }
public frmRegisterSubject() { InitializeComponent(); server.Service1 myservice = new server.Service1(); BindingSource source = new BindingSource(); List <server.Subject> s = myservice.getSubjects().ToList(); source.DataSource = s; lblName.Text = myservice.loggedInStudent().Name; gvRegisterSubjects.DataSource = source; }