关于GRIDVIEW 选中行的问题
我在gridview中的第一行为checkbox
public List<ListRecord> SelectChecked()
{
List<ListRecord> list = new List<ListRecord>();
foreach (DataGridViewRow dr in dgvExport.Rows)
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells[0];
if (cbx.Selected == true)
{
ListRecord lr = new ListRecord();
// lr.RecordingFileName
lr = (ListRecord)dgvExport.SelectedRows[cbx.RowIndex].DataBoundItem;
//把选中行的对象
list.Add(lr);
}
}
return list;
}
总是提示我索引越界,[cbx.RowIndex]这里面的值就是当前行的索引。但为什么总提示越界呢?