public void AddNew2() { if (TestHelper.RunningOnUnix) { Assert.Ignore("Fails at the moment due to a System.Data constraint violation"); } DataSet data_source = CreateRelatedDataSet(); BindingContext bc = new BindingContext(); CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager; DataView dv = cm.List as DataView; event_num = current_changed = position_changed = -1; cm.CurrentChanged += new EventHandler(CurrentChanged); cm.PositionChanged += new EventHandler(PositionChanged); cm.ItemChanged += new ItemChangedEventHandler(ItemChanged); dv.ListChanged += new ListChangedEventHandler(ListChanged); Assert.AreEqual(0, cm.Position, "AddNew1"); Assert.AreEqual(10, cm.Count, "AddNew2"); cm.AddNew(); Assert.AreEqual(10, cm.Position, "AddNew3"); Assert.AreEqual(11, cm.Count, "AddNew4"); // this does an implicit EndCurrentEdit cm.AddNew(); Assert.AreEqual(11, cm.Position, "AddNew5"); Assert.AreEqual(12, cm.Count, "AddNew6"); }
private void btnNew_Click(object sender, EventArgs e) { // some important notes // 1- when we use cm.AddNew() anew row is inserted and that will be shown in the datagridview so // cm.count will be increase by 1; // 2- cm.EndCurrentEdit(); // the category is modified to the source dt // the cm.EndCurrentEdit() is used to perform the add or the modify in the source which in that case dt int t = cm.Count; int h = cm.Position; cm.AddNew(); cm.Position = cm.Count - 1; lblPos.Text = (cm.Position + 1) + "/" + cm.Count; btnNew.Enabled = false; btnDel.Enabled = false; btnModify.Enabled = false; btnAdd.Enabled = true; btnCancel.Enabled = true; // we want the index of the last row in the dt (source) after we call cm.AddNew() the count of // cm will be increased by 1 and the source of cm which is dt also will be increased so we subtract by 2 // and at that point is the difference between BindingManagerBase and CurrencyManager int ind = Convert.ToInt32(dt.Rows[dt.Rows.Count - 2][0]) + 1; // - 2 it will be - 1 if we use b {look up} txtCatId.Text = ind.ToString(); txtCatName.Focus(); }
public void AddNew() { DataSet data_source = CreateRelatedDataSet(); BindingContext bc = new BindingContext(); CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager; event_num = current_changed = position_changed = -1; cm.CurrentChanged += new EventHandler(CurrentChanged); cm.PositionChanged += new EventHandler(PositionChanged); cm.ItemChanged += new ItemChangedEventHandler(ItemChanged); list_changed_called = false; cm.ListChanged += new ListChangedEventHandler(ListChangedEvent); Assert.AreEqual(0, cm.Position, "AddNew1"); Assert.AreEqual(10, cm.Count, "AddNew2"); Assert.AreEqual(cm.Count, cm.List.Count, "AddNew2.5"); cm.AddNew(); Assert.AreEqual(10, cm.Position, "AddNew3"); Assert.AreEqual(11, cm.Count, "AddNew4"); Assert.AreEqual(cm.Count, cm.List.Count, "AddNew4.5"); Assert.AreEqual(0, item_changed, "AddNew5"); Assert.AreEqual(-1, item_changed_args.Index, "AddNew6"); Assert.AreEqual(1, current_changed, "AddNew7"); Assert.AreEqual(2, position_changed, "AddNew8"); Assert.AreEqual(true, list_changed_called, "AddNew9"); Assert.AreEqual(-1, list_changed_args.OldIndex, "AddNew10"); Assert.AreEqual(10, list_changed_args.NewIndex, "AddNew11"); cm.CurrentChanged -= new EventHandler(CurrentChanged); cm.PositionChanged -= new EventHandler(PositionChanged); cm.ListChanged -= new ListChangedEventHandler(ListChangedEvent); }
private void btnThemMoi_Click(object sender, EventArgs e) { gridView_G.ActiveFilter.Clear(); gridViewCT.ActiveFilter.Clear(); dtmNgayXuat.Focus(); m_IsAddNew = true; BackgroundWorker bw = new BackgroundWorker(); XoaDuLieu(); bw.DoWork += delegate { maxid = dm.LaySoMaxHD("HOADONXUAT"); }; bw.RunWorkerCompleted += delegate { txtMaHoaDonXuat.EditValue = string.Format(@"{0}{1}/{2}", DateTime.Now.Month, DateTime.Now.Year, maxid + 1); }; bw.RunWorkerAsync(); bw.Dispose(); KhoaButton(true); TongTien = 0; m_CmG.AddNew(); idGoc = soid_goc + 1; ((DataRowView)m_CmG.Current).Row["IDHDX"] = idGoc; //Setedit m_CmG.EndCurrentEdit(); }
private void AddNewButton_Click(object sender, EventArgs e) { //Add new CurrentPosition = titlesManager.Position; titlesManager.AddNew(); state = "add"; }
private void btnThemMoi_Click(object sender, EventArgs e) { gridView_G.ActiveFilter.Clear(); gridViewCT.ActiveFilter.Clear(); dtmNgayLapHoaDon.Focus(); m_IsAddNew = true; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += delegate { maxid = dm.LaySoMaxHD("HOADONXUAT"); }; bw.RunWorkerCompleted += delegate { txtMaHoaDonXuat.EditValue = string.Format(@"{0}{1}/{2}", DateTime.Now.Month, DateTime.Now.Year, maxid + 1); }; bw.RunWorkerAsync(); bw.Dispose(); KhoaButton(true); TongTien = 0; m_CmG.AddNew(); DataRow rw = ((DataRowView)m_CmG.Current).Row; rw["IDHDX"] = Convert.ToInt32(dm.DanhMuc_TOPID("IDHDX", "HOADONXUAT").Rows[0]["MAXID"]) + 1; m_CmG.EndCurrentEdit(); m_CmCT.AddNew(); m_CmCT.EndCurrentEdit(); }
private void btnAddNew_Click(object sender, EventArgs e) { currentPosition = titlesManager.Position; SetAppState("Add"); titlesManager.AddNew(); appState = "Add"; }
// <Snippet1> private void AddListItem() { // Get the CurrencyManager for a DataTable. CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[DataTable1]; myCurrencyManager.AddNew(); }
private void btnAdd_Click(object sender, EventArgs e) { myBookmark = inventoryManager.Position; picItem.Image = null; chkEngraved.DataBindings.Clear(); chkEngraved.Checked = false; SetState("Add"); inventoryManager.AddNew(); }
internal void AddNew(RadTreeNode item) { if (item.Parent == null) { return; } if (item.Parent.BoundIndex == 0) { SuspendUpdate(); RadTreeNode newNode = this.TreeView.ListSource.AddNew(); newNode.Parent = item.Parent; newNode.BoundIndex = item.Parent.BoundIndex; newNode.ParentValue = this.TreeView.BoundDescriptors[newNode.Parent.BoundIndex].ChildDescriptor.GetValue(newNode.Parent.DataBoundItem); newNode.Text = item.Text; item.Parent = null; item.NodesLoaded = true; item.TreeViewElement = null; if (rootIndex.Count > 0) { ParentComparer comp = new ParentComparer(); if (comp.Compare(newNode, rootIndex[0]) <= 0) { this.TreeView.ListSource.Remove(newNode); if (this.TreeView != null) { this.TreeView.SetError("Invalid Parent or Child Value. Can not build self-reference relation.", newNode.Parent); } ResumeUpdate(); return; } } this.rootIndex.Add(newNode); ResumeUpdate(); return; } SuspendUpdate(); CurrencyManager cm = this.relationBindings[item.Parent.BoundIndex]; AvlTree <RadTreeNode> nodes = this.relationIndex[item.Parent.BoundIndex]; cm.AddNew(); RadTreeNode childNode = this.TreeView.CreateNewNode(); ((IDataItem)childNode).DataBoundItem = cm.List[cm.Count - 1]; childNode.Parent = item.Parent; childNode.ParentValue = this.TreeView.BoundDescriptors[childNode.Parent.BoundIndex].ChildDescriptor.GetValue(childNode.Parent.DataBoundItem); childNode.Text = item.Text; item.Parent = null; item.NodesLoaded = true; item.TreeViewElement = null; ResumeUpdate(); }
private void btnAddNew_Click(object sender, EventArgs e) { CurrentPosition = titlesManager.Position; SetAppState(State.Add); titlesManager.AddNew(); for (int i = 0; i < 4; i++) { authorsCombo[i].SelectedIndex = -1; } }
/// <summary> /// Init data /// </summary> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> private void InitData() { dt = bo.GetSchemaTable(); _manager = (CurrencyManager)this.BindingContext[dt]; _manager.AddNew(); _manager.Position = 0; BindDataToControl(); bln_IsEdit = false; ep.DataSource = dt; }
private void btnAddNew_Click(object sender, EventArgs e) { try { CurrentPosition = publishersManager.Position; publishersManager.AddNew(); setAppState(State.Add); } catch (Exception ex) { MessageBox.Show(ex.Message, "Record Addition Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAddNew_Click(object sender, EventArgs e) { try { myBookmark = publishersManager.Position; publishersManager.AddNew(); SetState("Add"); } catch (Exception ex) { MessageBox.Show("Error adding record.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAddNew_Click(object sender, EventArgs e) { try { CurrentPosition = pubManager.Position; pubManager.AddNew(); SetAppState("Add"); AppState = "Add"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Adding Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { try { moduleManager.AddNew(); MessageBox.Show("Populate the text boxes and Click the Save button when you have finished entering the data", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //user will get new blank slot to populate and then can save new record by pressing save } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding new record", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAddNew_Click(object sender, EventArgs e) { cboAuthor1.SelectedIndex = -1; cboAuthor2.SelectedIndex = -1; cboAuthor3.SelectedIndex = -1; cboAuthor4.SelectedIndex = -1; try { myBookmark = titlesManager.Position; titlesManager.AddNew(); SetState("Add"); } catch (Exception ex) { MessageBox.Show("Error adding record.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void EndAddNew() { #if NET_2_0 if (TestHelper.RunningOnUnix) { Assert.Ignore("Fails with 2.0 profile"); } #endif DataSet data_source = CreateRelatedDataSet(); BindingContext bc = new BindingContext(); CurrencyManager cm = bc [data_source.Tables["Table1"], ""] as CurrencyManager; data_source.Tables["Table1"].DefaultView.ListChanged += new ListChangedEventHandler(DataView_ListChanged); event_num = current_changed = position_changed = -1; cm.CurrentChanged += new EventHandler(CurrentChanged); cm.PositionChanged += new EventHandler(PositionChanged); cm.ItemChanged += new ItemChangedEventHandler(ItemChanged); Assert.AreEqual(0, cm.Position, "EndAddNew1"); Assert.AreEqual(10, cm.Count, "EndAddNew2"); cm.AddNew(); Console.WriteLine("position = {0}", cm.Position); Assert.AreEqual(0, item_changed, "EndAddNew3"); Assert.AreEqual(-1, item_changed_args.Index, "EndAddNew4"); Assert.AreEqual(1, current_changed, "EndAddNew5"); Assert.AreEqual(2, position_changed, "EndAddNew6"); cm.EndCurrentEdit(); Console.WriteLine("position = {0}", cm.Position); Assert.AreEqual(3, item_changed, "EndAddNew7"); Assert.AreEqual(-1, item_changed_args.Index, "EndAddNew8"); Assert.AreEqual(1, current_changed, "EndAddNew9"); Assert.AreEqual(2, position_changed, "EndAddNew10"); Assert.AreEqual(10, cm.Position, "EndAddNew11"); Assert.AreEqual(11, cm.Count, "EndAddNew12"); cm.CurrentChanged -= new EventHandler(CurrentChanged); cm.PositionChanged -= new EventHandler(PositionChanged); }
private void btnNew_Click(object sender, EventArgs e) { newCustomer = true; txtFirstName.ReadOnly = false; txtLastName.ReadOnly = false; txtAddress.ReadOnly = false; txtCity.ReadOnly = false; txtState.ReadOnly = false; txtZip.ReadOnly = false; btnNew.Enabled = false; btnSave.Enabled = true; btnCancel.Enabled = true; savedIndex = cboCustomers.SelectedIndex; cboCustomers.SelectedIndex = -1; cboCustomers.Enabled = false; customersManager.AddNew(); txtFirstName.Focus(); }
private void btnThemMoi_Click(object sender, EventArgs e) { XoaDuLieu(); //flag = true; tongtien = 0; lkpThueVAT.EditValue = Convert.ToDecimal(5); KhoaButton(true); m_IsAddNew = true; m_CmG.AddNew(); m_CmCT.AddNew(); idGoc = soid_goc + 1; ((DataRowView)m_CmG.Current).Row["IDHDN"] = idGoc; //Setedit m_CmG.EndCurrentEdit(); m_CmCT.EndCurrentEdit(); soid_goc = idGoc; txtMSHĐ.Focus(); }
public void CancelAddNew() { if (TestHelper.RunningOnUnix) { Assert.Ignore("Fails at the moment"); } DataSet data_source = CreateRelatedDataSet(); BindingContext bc = new BindingContext(); CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager; DataView dv = cm.List as DataView; event_num = current_changed = position_changed = -1; cm.CurrentChanged += new EventHandler(CurrentChanged); cm.PositionChanged += new EventHandler(PositionChanged); cm.ItemChanged += new ItemChangedEventHandler(ItemChanged); dv.ListChanged += new ListChangedEventHandler(ListChanged); Assert.AreEqual(0, cm.Position, "CancelAddNew1"); Assert.AreEqual(10, cm.Count, "CancelAddNew2"); Assert.AreEqual(cm.Count, cm.List.Count, "AddNew2.5"); cm.AddNew(); Assert.AreEqual(0, item_changed, "CancelAddNew3"); Assert.AreEqual(-1, item_changed_args.Index, "CancelAddNew4"); Assert.AreEqual(1, current_changed, "CancelAddNew5"); Assert.AreEqual(2, position_changed, "CancelAddNew6"); cm.CancelCurrentEdit(); Assert.AreEqual(6, item_changed, "CancelAddNew7"); Assert.AreEqual(9, item_changed_args.Index, "CancelAddNew8"); Assert.AreEqual(3, current_changed, "CancelAddNew9"); Assert.AreEqual(4, position_changed, "CancelAddNew10"); Assert.AreEqual(9, cm.Position, "CancelAddNew11"); Assert.AreEqual(10, cm.Count, "CancelAddNew12"); Assert.AreEqual(cm.Count, cm.List.Count, "AddNew12.5"); cm.CurrentChanged -= new EventHandler(CurrentChanged); cm.PositionChanged -= new EventHandler(PositionChanged); }
private void btnNew_Click(object sender, EventArgs e) { // زر تفريغ الخانات وعمل حقل جديد فارغ cm.AddNew(); txtIDName.Focus(); }
/// <summary> /// Save data into database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> private void btnSave_Click(object sender, System.EventArgs e) { if (_manager != null) { _manager.EndCurrentEdit(); } ep.SetError(txtConfirmPassword, null); if (txtPassword.Text != txtConfirmPassword.Text) { ep.SetError(txtConfirmPassword, clsResources.GetMessage("errors.compare.equal", lblConfirmPassword.Text, lblPassword.Text)); return; } if (User != null && User.RowState == DataRowState.Unchanged) { return; } if (bln_IsEdit) { txtUserName.Text = txtUserName.Text.Trim(); if (ValidateData()) { try { if (bo.Update(User) > 0) { MessageBox.Show(clsResources.GetMessage("messages.save.success"), clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Information); Success = true; this.Close(); } else { MessageBox.Show(clsResources.GetMessage("messages.save.fail"), clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Error); Success = false; } } catch (Exception ex) { MessageBox.Show(clsResources.GetMessage("messages.save.fail") + "\r\nDetail: " + ex.Message, clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { txtUserName.Text = txtUserName.Text.Trim(); if (ValidateData()) { try { if (bo.Insert(User) > 0) { MessageBox.Show(clsResources.GetMessage("messages.save.success"), clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Information); Success = true; //Do du lieu //_manager.RemoveAt(0); //dt.AcceptChanges(); //dt.Rows.Clear(); _manager.AddNew(); //dt.AcceptChanges(); txtConfirmPassword.Text = ""; //dt.Rows.Add(dt.NewRow()); //_manager.Position = 0; //cboStatus.SelectedIndex = -1; //cboURoleID.SelectedIndex = -1; //this.Close(); } else { MessageBox.Show(clsResources.GetMessage("messages.save.fail"), clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Error); Success = false; } } catch (Exception ex) { MessageBox.Show(clsResources.GetMessage("messages.save.fail") + "\r\nDetail: " + ex.Message, clsResources.GetMessage("messages.general"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
//-----------工具栏控制代码------------- protected void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if (e.Button.ToolTipText == "退出") { this.Close(); } if (e.Button.ToolTipText == "首记录") { this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行 cmOrders.Position = 0; this.dataGrid1.Select(cmOrders.Position); //选中当前行 this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标 return; } if (e.Button.ToolTipText == "上一记录") { if (cmOrders.Position >= 0) { this.dataGrid1.UnSelect(cmOrders.Position); cmOrders.Position--; this.dataGrid1.Select(cmOrders.Position); this.dataGrid1.CurrentRowIndex = cmOrders.Position; } return; } if (e.Button.ToolTipText == "下一记录") { if (cmOrders.Position <= cmOrders.Count - 1) { this.dataGrid1.UnSelect(cmOrders.Position); cmOrders.Position++; this.dataGrid1.Select(cmOrders.Position); this.dataGrid1.CurrentRowIndex = cmOrders.Position; } return; } if (e.Button.ToolTipText == "尾记录") { this.dataGrid1.UnSelect(cmOrders.Position); cmOrders.Position = cmOrders.Count - 1; this.dataGrid1.Select(cmOrders.Position); this.dataGrid1.CurrentRowIndex = cmOrders.Position; return; } if (e.Button.ToolTipText == "新增") { cmOrders.AddNew(); //新增一条记录 SetDefaultValue(); //设置默认值 SetModifyMode(true); //设置控件只读等属性 } if (e.Button.ToolTipText == "修改") { SetModifyMode(true); } if (e.Button.ToolTipText == "删除") { DialogResult result = MessageBox.Show("确认删除?", "删除数据", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { if (cmOrders.Count > 0) //立即从数据集中删除 { cmOrders.RemoveAt(cmOrders.Position); da1.Update(dataSet11); } else { MessageBox.Show("表中为空,已无可删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (e.Button.ToolTipText == "提交") { bool canSubmit; canSubmit = this.CheckNotNull(); if (canSubmit == false) //有非空值字段为空,不允许提交 { return; } cmOrders.EndCurrentEdit(); if (dataSet11.GetChanges() != null) { try { da1.Update(dataSet11); SetModifyMode(false); } catch (Exception express) { MessageBox.Show(express.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); dataSet11.RejectChanges(); } } return; } if (e.Button.ToolTipText == "取消") { try { cmOrders.CancelCurrentEdit(); //取消编辑 SetModifyMode(false); } catch (Exception express) { MessageBox.Show(express.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } }
private void btnAdd_Click(object sender, EventArgs e) { myBookmark = phoneManager.Position; SetState("Add"); phoneManager.AddNew(); }
/// <summary> /// Is called when (un)checking items of the listbox. updates the datasource relation table /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BoundCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { if (!ready) { return; } if (e.Index < 0 || e.Index >= this.Items.Count) { return; } //just in case someone adds items manually //do not do that! if (this.Items[e.Index].GetType() != typeof(ListBoxItem)) { return; } //find the currently selected ID in the parent table object parentID = null; object childID = ((ListBoxItem)this.Items[e.Index]).Value; try { //do we always have type datarowview?! //another solution is parentDataManager.GetItemProperties().Find(parentIDMember, false).GetValue(parentDataManager.List[parentDataManager.Position]); //currencymanager.current shows buggy behavior sometimes when used with tostring() DataRowView drv = (DataRowView)this.parentDataManager.Current; parentID = drv[this.parentIDMember]; } catch (Exception) { } if (parentID == null || childID == null) { return; } ArrayList rows = new ArrayList(); PropertyDescriptorCollection relationProps = relationDataManager.GetItemProperties(); PropertyDescriptor parentValue = relationProps.Find(parentValueMember, false); PropertyDescriptor childValue = relationProps.Find(childValueMember, false); //find row(s) with current parentID and childId of item being (un)checked for (int i = 0; i < relationDataManager.Count; i++) { object row = relationDataManager.List[i]; object val = parentValue.GetValue(row); if (!parentID.Equals(val)) { continue; } val = childValue.GetValue(row); if (childID.Equals(val)) { rows.Add(row); } } if (e.NewValue == CheckState.Checked) { //case: changing to checked state bool exists = false; foreach (DataRowView curRow in rows) { //just in case of more than one row with same IDs, keep only one if (exists) { curRow.Delete(); } //TODO: we should rather undelete deleted rows than always create new ones and delete them //means we might end in having several deleted rows with same ids //but how to get hands on 'em?! maybe through dataview or sth. /*if (curRow.Row.RowState == DataRowState.Deleted) * curRow.Row. * continue;*/ if (curRow.Row.RowState != DataRowState.Deleted && curRow.Row.RowState != DataRowState.Detached) { exists = true; } } //if none was found, which should be the normal case, create one //attention! assign allownull to your colums in your dataset or assign proper default values if (!exists) { relationDataManager.AddNew(); ((DataRowView)relationDataManager.Current)[parentValueMember] = parentID; ((DataRowView)relationDataManager.Current)[childValueMember] = childID; } } else if (e.NewValue == CheckState.Unchecked) { //case: changing to unchecked state //delete all concerned rows foreach (DataRowView curRow in rows) { if (curRow.Row.RowState == DataRowState.Deleted) { continue; } else { curRow.Delete(); } } } }
private void btnAddNew_Click(object sender, EventArgs e) { rentalManager.AddNew(); SetState("Add"); addTicket = true; }
private void button2_Click(object sender, EventArgs e) { cm.AddNew(); txtid.Focus(); }
/// <summary> /// Handle events when click on btnAdd, btnDelete, btnSave, btnCancel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> private void EventListener(object sender, EventArgs e) { if (_manager == null) { return; } if (sender == btnAdd) { dt.DefaultView.AllowNew = true; _manager.AddNew(); grd.Focus(); dt.DefaultView.AllowNew = false; return; } if (_manager.Position < 0) { return; } _manager.EndCurrentEdit(); if (sender == btnDelete) { int i = _manager.Position; DataRow row = dt.Rows[i]; string rowID = row["UROLE_ID"].ToString(); DataTable checkedTbl = new clsUserRoleBO().CheckIsExistAcount(rowID); if (checkedTbl != null && checkedTbl.Rows.Count > 0) { MessageBox.Show("You can not delete this role, because \n it contains User's account already.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (_manager.Position == -1) { return; } if (MessageBox.Show( clsResources.GetMessage("warnings.delete", ""), clsResources.GetMessage("warnings.general"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes ) { dt.DefaultView.AllowDelete = true; _manager.Position = 0; _manager.RemoveAt(i); dt.DefaultView.AllowDelete = false; try { if (i < _manager.Count) { _manager.Position = i; } else { _manager.Position = i - 1; } } catch { } } } } if (sender == btnCancel) { dt.RejectChanges(); DataRow[] rows = dt.GetErrors(); foreach (DataRow row in rows) { row.ClearErrors(); } } else if (sender == btnSave) { UpdateAll(dt); } }