代码如下:
int index = this.UserDgv.SelectedRows[0].Index;
//int index = UserDgv.SelectedRows[0].Index;
//初始化编辑通讯录的窗体并打开
UpdateAddForm newform = new UpdateAddForm();
//向编辑通讯录的窗体传递参数
newform.UserIDStr = UserDgv.Rows[index].Cells["UserID"].Value.ToString();
newform.UserNameStr = UserDgv.Rows[index].Cells["UserName"].Value.ToString();
newform.UserSexStr = UserDgv.Rows[index].Cells["UserSex"].Value.ToString();
newform.UserAreaStr = UserDgv.Rows[index].Cells["UserArea"].Value.ToString();
newform.UserEmailStr = UserDgv.Rows[index].Cells["UserEmail"].Value.ToString();
//打开新窗体
newform.ShowDialog();
FillUserInfor();
int index = this.UserDgv.SelectedRows[0].Index;
//int index = UserDgv.SelectedRows[0].Index;
//初始化编辑通讯录的窗体并打开
UpdateAddForm newform = new UpdateAddForm();
//向编辑通讯录的窗体传递参数
newform.UserIDStr = UserDgv.Rows[index].Cells["UserID"].Value.ToString();
newform.UserNameStr = UserDgv.Rows[index].Cells["UserName"].Value.ToString();
newform.UserSexStr = UserDgv.Rows[index].Cells["UserSex"].Value.ToString();
newform.UserAreaStr = UserDgv.Rows[index].Cells["UserArea"].Value.ToString();
newform.UserEmailStr = UserDgv.Rows[index].Cells["UserEmail"].Value.ToString();
//打开新窗体
newform.ShowDialog();
FillUserInfor();
参数名:index我测试过编辑其他行的时候都没有报错,只有第一行的时候出错了
参数名: index
在 System.Collections.ArrayList.get_Item(Int32 index)
在 System.Windows.Forms.DataGridViewSelectedRowCollection.get_Item(Int32 index)
在 SendMail.AddManageForm.button2_Click(Object sender, EventArgs e) 位置 E:\SendMail\SendMail\SendMail\AddManageForm.cs:行号 50
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
这句话看不懂。
你每次取的都是第一行啊,没有变啊
int index = this.UserDgv.SelectedRows[CurrentRow.Index].Index;
还差不多吧,index是一个变的数字吧
try
{ //获得修改行的索引
int index = this.UserDgv.SelectedRows[0].Index;
//int index = UserDgv.SelectedRows[0].Index;
//初始化编辑通讯录的窗体并打开
UpdateAddForm newform = new UpdateAddForm();
//向编辑通讯录的窗体传递参数
newform.UserIDStr = UserDgv.Rows[index].Cells["UserID"].Value.ToString();
newform.UserNameStr = UserDgv.Rows[index].Cells["UserName"].Value.ToString();
newform.UserSexStr = UserDgv.Rows[index].Cells["UserSex"].Value.ToString();
newform.UserAreaStr = UserDgv.Rows[index].Cells["UserArea"].Value.ToString();
newform.UserEmailStr = UserDgv.Rows[index].Cells["UserEmail"].Value.ToString();
//打开新窗体
newform.ShowDialog();
FillUserInfor();
}
catch (Exception ex)
{
Console.WriteLine(ex);
UpdateAddForm newform = new UpdateAddForm();
//向编辑通讯录的窗体传递参数
newform.UserIDStr = UserDgv.Rows[0].Cells["UserID"].Value.ToString();
newform.UserNameStr = UserDgv.Rows[0].Cells["UserName"].Value.ToString();
newform.UserSexStr = UserDgv.Rows[0].Cells["UserSex"].Value.ToString();
newform.UserAreaStr = UserDgv.Rows[0].Cells["UserArea"].Value.ToString();
newform.UserEmailStr = UserDgv.Rows[0].Cells["UserEmail"].Value.ToString();
//打开新窗体
newform.ShowDialog();
FillUserInfor();
}
你每次取的都是第一行啊,没有变啊
他这是取了么?他没选哪来的值?而且这种写法有么SelectedRows[0].
你try catch有什么用?根本就不符合自己的要求。
try catch只是要捕捉不可预知的错误,你try什么啊。现在知道有错误,要找出来。