Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //離開Cell之前,會觸發驗證,驗證事件的好處是,他可以把這個事件保留,不讓你往下一個動做下去
- //有底類似,你點了一個Cell然後你又點了其他的Cell,然後會觸發這個事件,只要不通過驗證的條件
- //就可以讓你下一個動作被取消,一直保持在這個動作上面,而且僅限操作的時候才會觸發,程式寫入
- //的時候並不會觸發
- private void DataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- if (e.FormattedValue.ToString() == "")
- {
- //設定Cell上錯誤的文字
- this.dataGridView1.Rows[3].Cells[3].ErrorText = "test";
- //把事件抓住,不讓下一個動作發生
- e.Cancel = true;
- }
- else
- {
- this.dataGridView1.Rows[3].Cells[3].ErrorText = "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement