c# - Index was out of range. Must be non-negative and less than the size of the collection. 4 -


my datagridview has 4 rows. row[2] has name of date1 , row[3] has name of date2. tested code cells[2] , cell[3] instead of cells name. again received same error. problem index not out of range. , less size of collection. code:

for (int = 0; < dgv1frmmodateeghamat.rows.count; i++)         {             datetime date1 = convert.todatetime(dgv1frmmodateeghamat.selectedrows[i].cells["date1"].value);              datetime date2 = convert.todatetime(dgv1frmmodateeghamat.selectedrows[i].cells["date2"].value);              timespan span = date2.subtract(date1);              int result = int.parse(span.totaldays.tostring());              if (result >= int.parse(textboxx2.text))             {                 dgv1frmmodateeghamat.selectedrows[i].visible = true;             }              else             {                  currencymanager cr = (currencymanager)bindingcontext[dgv1frmmodateeghamat.datasource];                 cr.suspendbinding();                  dgv1frmmodateeghamat.selectedrows[i].visible = false;             }         } 

but see error: index out of range. must non-negative , less size of collection.

you looping through rows indexing selectedrows. need loop through selectedrows.

for (int = 0; < dgv1frmmodateeghamat.selectedrows.count; i++) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -