我在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]这里面的值就是当前行的索引。但为什么总提示越界呢?
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]这里面的值就是当前行的索引。但为什么总提示越界呢?
==========
lr = (ListRecord)dr .DataBoundItem;
这个方法写在按钮事件里的
这句话越界了。
dgvExport.SelectedRows这个已经是选中的行了。后面的 [cbx.RowIndex]应该是列号。你这里
cbx.RowIndex应该是行号。行号一旦比较大。肯定是越界了。
对了。像你这样的高手。去我的帖子里面看看。帮我解决一下问题啊。我提的问题没人看。
http://topic.csdn.net/u/20100825/09/03fb359d-51d9-41d4-a86b-9cbc5a1e775b.html?seed=1338331056&r=67918894
关于内存溢出的。还没找到解决办法
try{}
catch { }