private void cmdSearch_Click(object sender, EventArgs e) { int iStartIndex = 0; if (dgvCity.CurrentCell != null) { if (0 <= dgvCity.CurrentCell.RowIndex) { iStartIndex = dgvCity.CurrentCell.RowIndex; } } if (dgvCity.Rows.Count - 1 <= iStartIndex) { MessageBox.Show("最後まで検索しました。", "検索終了", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //検索本体 string sPat = "^" + txtSearch.Text; for (int i = iStartIndex; i < _blCity.Count; i++) { cCity c = _blCity[i]; if (Regex.IsMatch(c.SearchStr, sPat)) { dgvCity.FirstDisplayedScrollingRowIndex = i; dgvCity.CurrentCell = dgvCity[4, i]; return; } } }
private void cmdAddNew_Click(object sender, EventArgs e) { if (MessageBox.Show("新規市町村を追加しますか?\n(一度追加を反映すると、データベースを外部ツールで直接編集しないと削除できません)", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No) { return; } cCity c = new cCity("9999", "9999", "99", "新規市区町村", "しんき"); _blCity.Add(c); dgvCity.FirstDisplayedScrollingRowIndex = _blCity.Count - 1; dgvCity.CurrentCell = dgvCity[4, _blCity.Count - 1]; }