Devexpress WinForm 增刪改,頁面傳值,無需重新繫結資料庫重新整理。
阿新 • • 發佈:2018-12-31
一.新增:
private void newBtn_Click(object sender, EventArgs e) { CIL_Currency_Add f7 = new CIL_Currency_Add("新增", "", ""); if (f7.ShowDialog() == DialogResult.OK) { if (CIL_Currency_Add.gc.tt == "true" ) { gridView1.AddNewRow(); } } //重複新增 while (CIL_Currency_Add.gc.btn == "true") { CIL_Currency_Add f8 = new CIL_Currency_Add("新增", "", ""); if (f8.ShowDialog() == DialogResult.OK) { if (CIL_Currency_Add.gc.tt == "true" ) { gridView1.AddNewRow(); } } } }二.刪除//批量刪除private void ManyDel_Click(object sender, EventArgs e) { if (MessageUtil.ShowYesNoAndTips("確認刪除?, 刪除的資訊無法恢復!!!") == DialogResult.Yes) { //獲取選擇行的RowHandle, int[] rowHandles = gridView1.GetSelectedRows(); for (int i = 0; i < rowHandles.Length; i++) { Mm.CurrencyCode = this.gridView1.GetRowCellValue(rowHandles[i], "CurrencyCode").ToString(); bool dd = Bb.Delete(Mm.CurrencyCode); } MessageUtil.ConfirmShow("操作成功"); } else { return;//即取消此操作。 } gridView1.DeleteSelectedRows(); }//行內刪除 private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { string CurrencyCode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CurrencyCode").ToString(); Mm.CurrencyCode = CurrencyCode; if (MessageUtil.ShowYesNoAndTips("確認刪除?, 刪除的資訊無法恢復!!!") == DialogResult.Yes) { bool dd = Bb.Delete(Mm.CurrencyCode); if (dd == true) { MessageUtil.ConfirmShow("操作成功"); gridView1.DeleteRow(gridView1.FocusedRowHandle); } else { MessageUtil.ShowTips("操作失敗"); } } else { return;//即取消此操作。 } }三.修改//行內修改 private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { string CurrencyCode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CurrencyCode").ToString(); string Txt = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Txt").ToString(); CIL_Currency_Add f7 = new CIL_Currency_Add("修改", CurrencyCode, Txt); if (f7.ShowDialog() == DialogResult.OK) { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Txt"], CIL_Currency_Add.gc.t2); } }四。接收傳值頁面
public CIL_Currency_Add(string button, string CurrencyCode, string Txt) : this() { Action = button; this.Text = Action; CurrencyCodeEdit.Text = CurrencyCode; TxtEdit.Text = Txt; }