|Column 1|Column 2|
|1 |1 |
|2 |2 |
|3 |3 |
|4 |4 |
|5 |5 |
|6 |6 |
|7 |7 |
|8 |8 |
|9 |9 |
| | |
比方說,我在我的datagridview顯示此,現在我添加新行(第10行)。我檢查用戶是否在以後使用該數據之前留下任何列,現在如果用戶在列1中插入了某些內容,並且將列2留空,我檢查並顯示他的消息「列2不能爲空」,但是在我希望他的選擇(currentrow)在該空單元格,我的問題是新行沒有索引(它有,但是當我使用它時,我得到錯誤,我不能使用大於最大值的索引行)。我該如何解決它。datagridview新行索引
這是我在哪裏檢查
int nRows = dataGridView1.Rows.Count;
int currColumn = dataGridView1.CurrentCell.ColumnIndex;
int currRow = dataGridView1.CurrentCell.RowIndex;
string id = dataGridView1.Rows[currRow].Cells[0].Value.ToString();
string opis = dataGridView1.Rows[currRow].Cells[1].Value.ToString();
if (string.IsNullOrEmpty(id))
{
MessageBox.Show("Polje broj ne moze biti prazno!");
dataGridView1.CurrentCell = dataGridView1[0, nRows];
}
else if (string.IsNullOrEmpty(opis))
{
MessageBox.Show("Polje opis ne moze biti prazno!");
dataGridView1.CurrentCell = dataGridView1[1, nRows];
}
這將是有益的,如果你發佈你所描述的代碼部分代碼。這使得它更容易幫助你 –
我添加後的代碼 – DoLoop