private void ToggleState() { if (btn_Them.Text.Equals("Thêm")) { btn_Them.Text = "Lưu Lại"; btn_capnhat.Enabled = false; btn_xoa.Enabled = false; btn_thoat.Text = "Hủy"; txtMa.Text = ""; txtMa.Enabled = true; txtMa.Focus(); txtMota.Text = ""; txtMota.Enabled = true; button1.Visible = false; button2.Visible = false; label3.Visible = false; creComboBox1.Visible = false; this.Refresh(); //creComboBox1.SelectedIndexChanged -= new System.EventHandler(this.creComboBox1_SelectedIndexChanged); return; } if (txtMa.Text.Equals("")) { Alert.Show("Bạn phải nhập mã danh mục", Color.Red); txtMa.Focus(); return; } services.InsertCategory(txtMa.Text, StaticClass.storeId, txtMota.Text); catagries = services.GetAllCategories(StaticClass.storeId); limit = catagries.Rows.Count - 1; for (int i = 0; i < catagries.Rows.Count; i++) { if (catagries.Rows[i][0].Equals(txtMa.Text)) { currentIndex = i; break; } } btn_Them.Text = "Thêm"; btn_capnhat.Enabled = true; btn_xoa.Enabled = true; btn_thoat.Text = "Thoát"; txtMa.Enabled = false; txtMota.SelectionStart = 0; txtMota.Focus(); txtMota.SelectionLength = txtMota.Text.Length; button1.Visible = true; button2.Visible = true; label3.Visible = true; creComboBox1.Visible = true; this.Refresh(); dataBinding(); creComboBox1.SelectedIndex = currentIndex; }