private void toolAdd_Click(object sender, EventArgs e) { DataGridViewRow row = new DataGridViewRow(); if (txtGroupName.Text != "") { txtGroupName.Focus(); string name = txtGroupName.Text; int code = Core.Group.GenerateCode(name); if (code == -1) { Core.Utility.Msg("Tên lớp " + name + "không hợp lệ."); return; } int index = Core.Ref.UniGroup.AddItem(new Core.Group(name, code)); row.CreateCells(gridGroup, name, code); row.Tag = index; gridGroup.Rows.Add(row); txtGroupName.Text = ""; } if (txtStudentName.Text != "") { txtStudentName.Focus(); int grpIndex = (int)gridGroup.Tag; if (grpIndex == -1) { Core.Utility.Msg("Vui lòng chọn một lớp trước khi nhập danh sách học sinh."); return; } Core.Group g = Core.Ref.UniGroup.Items[grpIndex]; Core.Student s = new Core.Student(g.Items.Length + 1, Core.Utility.ValidName(txtStudentName.Text)); row.Tag = g.AddItem(s); row.CreateCells(gridStudent, s.no, s.name); int index = gridStudent.Rows.Add(row); gridStudent.ClearSelection(); int oldGridHeight = gridStudent.Height; gridStudent.Height = 2 * 22; gridStudent.FirstDisplayedScrollingRowIndex = index; gridStudent.Height = oldGridHeight; txtStudentName.Text = ""; } }
/// <summary> /// Hiển thị danh sách lớp tương ứng khi chọn một lớp /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gridGroup_RowEnter(object sender, DataGridViewCellEventArgs e) { object index = gridGroup.Rows[e.RowIndex].Tag; gridStudent.Rows.Clear(); if (index == null) { // Đây là ô trống để thêm bản ghi mới gridGroup.Tag = -1; return; } gridGroup.Tag = index; Core.Group g = Core.Ref.UniGroup.Items[(int)index]; for (int i = 0; i < g.Items.Length; i++) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(gridStudent, g.Items[i].no, g.Items[i].name); row.Tag = i; gridStudent.Rows.Add(row); } }
private void FormGroups_Load(object sender, EventArgs e) { // Thêm vào menu Window cửa sổ này //ToolStripMenuItem mnuItemWindowGroup = new ToolStripMenuItem(); //mnuItemWindowGroup.Text = "Lớp học"; //mnuItemWindowGroup.ShortcutKeys = (Keys)(Keys.Alt | Keys.F7); //mnuItemWindowGroup.ShowShortcutKeys = true; //mnuItemWindowGroup.Click += new EventHandler(mnuItemWindowGroup_Click); //MenuStrip menuAll = (MenuStrip)this.MdiParent.MainMenuStrip; //ToolStripMenuItem mnuWindow = (ToolStripMenuItem)menuAll.Items["mnuWindow"]; //((Hashtable)this.Tag).Add("WindowIndex", mnuWindow.DropDownItems.Add(mnuItemWindowGroup)); // Đưa danh sách lớp vào grid for (int i = 0; i < Core.Ref.UniGroup.Items.Length; i++) { Core.Group g = Core.Ref.UniGroup.Items[i]; DataGridViewRow row = new DataGridViewRow(); row.CreateCells(gridGroup, g.name, g.code); row.Tag = i; // chứa index của lớp trong UniGroup gridGroup.Rows.Add(row); } // Tag của grid sẽ chứa những group thêm và sửa đổi cùng trạng thái gridGroup.Tag = -1; }