//moneyDataTableにデータを追加するメソッド private void AddData() { //登録画面の表示 ItemForms itemForms = new ItemForms(categoryDataSet1); DialogResult dialogResult = itemForms.ShowDialog(); //登録ボタンを押した場合 if (dialogResult == DialogResult.OK) { //金額のTextBoxで金額入力しなかった場合 if (string.IsNullOrEmpty(itemForms.mtxtMoney.Text)) { MessageBox.Show("金額を入れてください。", "入力ミス!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //入力したデータをDataGridViewに表示させる処理 else { moneyDataSet.moneyDataTable.Rows.Add(itemForms.monCalendar.SelectionRange.Start, itemForms.cmbCategory.Text, itemForms.txtItem.Text, int.Parse(itemForms.mtxtMoney.Text), itemForms.txtRemarks.Text); } } }
//データ変更を行う処理 private void UpdateData() { int selectRow = dgv.CurrentRow.Index; //データGridviewに前回格納してたデータを取得する ItemForms update = new ItemForms(categoryDataSet1, DateTime.Parse(dgv.CurrentRow.Cells[0].Value.ToString()), dgv.CurrentRow.Cells[1].Value.ToString(), dgv.CurrentRow.Cells[2].Value.ToString(), dgv.CurrentRow.Cells[3].Value.ToString(), dgv.CurrentRow.Cells[4].Value.ToString()); //取得したデータを登録画面のそれぞれのTextboxに表示する DialogResult diaResult = update.ShowDialog(); if (diaResult == DialogResult.OK) { //金額のTextBoxで金額入力しなかった場合 if (string.IsNullOrEmpty(update.mtxtMoney.Text)) { MessageBox.Show("金額を入れてください。", "入力ミス!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //変更したデータをDataGridViewに表示させる処理 else { dgv.CurrentRow.Cells[0].Value = update.monCalendar.SelectionRange.Start; dgv.CurrentRow.Cells[1].Value = update.cmbCategory.Text; dgv.CurrentRow.Cells[2].Value = update.txtItem.Text; dgv.CurrentRow.Cells[3].Value = int.Parse(update.mtxtMoney.Text); dgv.CurrentRow.Cells[4].Value = update.txtRemarks.Text; } } }