c#中怎么获取DataGrid里面数据的当前行的索引?

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:32:38
我把数据集加载到dataGrid里面以后,我点击删除按钮之后就把我所选的当前行给删除,可是我不知道怎么获取DataGrid里面数据的当前行的索引?

1。将DataGrid的Datakeys属性设置成表(假设是stu_information)的主键值(假设是stu_ID)
2。添加DataGrid的DeleteCommand事件
3。Command对象的执行字符串为
string delCmd="DELETE FROM stu_information WHERE stu_ID='"+DataGrid1.DataKeys[e.Item.ItemIndex]+"'";

其他的步骤你肯定会
你试试吧, 我这样成功了

DataGrid datagrid1;
datagrid1.CurrentRowIndex;