저는 프로그래밍에 비교적 익숙하지 않으므로 쉽게 할 수 있습니다!데이터 격자 반복 오류입니다. Exit For 루프 때 null입니까?
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
어떻게 Dataagridview를 반복 처리 한 후에 이러한 오류가 발생하지 않도록 할 수 있습니까? 코드는 정확히 필요한 것을 수행합니다. for 루프는 모든 행을 반복했지만 행이 남아 있지 않으면 예외를 throw합니다. 모든 행이 변환되면 어떻게 나갈 수 있습니까?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
//String header = gridview_id.Columns[i].HeaderText;
// String cellText = row.Cells[i].Text;
partData.partID = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
partData.productName = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
partData.partDescription = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);
partData.unitPrice = Convert.ToString(dataGridView1.Rows[i].Cells[3].Value);
partData.quantity = Convert.ToString(dataGridView1.Rows[i].Cells[4].Value);
partData.partNote = Convert.ToString(dataGridView1.Rows[i].Cells[5].Value);
MessageBox.Show(PerformRequestUpdatePriority("http://dmcalla04.students.qub.ac.uk/import.php?", username, partData.partID, partData.productName, partData.partDescription, partData.unitPrice, partData.quantity, partData.partNote));
Console.WriteLine(username);
}
}
많은 분들께 미리 감사드립니다.
안녕하세요. 도움을 주셔서 감사합니다. 하지만 이건 행렬 때문에 작동하지 않습니다. 셀 []. 그것은 밑줄이 그어져 있습니다. '객체에는 세포에 대한 정의가 없습니다 ......'등 어떤 다른 제안입니까? –
@DeanCosgrove [이 링크] (https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.cells (v = vs.110) .aspx)를 기반으로하고 또한 코드' DataGridViewRow'는'Cells'라는 속성을 가지고 있습니다. 대소 문자가 정확하다는 것을 확인할 수 있습니까? 당신이 셀 번호를 하드 코드 했으므로 두 번째 루프가 필요 없기 때문에 코드를 업데이트했습니다. – manman
그래도 여전히 작동하지 않는 것을 확인할 수 있습니다. (이 속성을 사용하여이 속성을 호출 할 수 없습니다. 도움 사람을 보내 주셔서 감사합니다. –