|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];
}
의
RowsAdded
이벤트에 가입 할 수 있음을 확인하고 코드 부분입니다 . 그게 더 쉽게 당신을 도울 수 –게시물에 코드를 추가했습니다 – DoLoop