我在 win 表单上有一个按钮,可以删除网格视图上的行。
numberSettingTable.SelectedRows[0]
问题是当我按下没有行选择的按钮时,它发送空值,在 java -1 中返回它告诉没有选择行。那么我怎样才能在 c# 中实现同样的效果呢?
我试过if语句
numberSettingTable.SelectedRows[0] != null
但它没有奏效。
以下是错误详情。
System.ArgumentOutOfRangeException 未处理 Message=Index 超出范围。必须是非负数且小于集合的大小。参数名称: index Source=mscorlib ParamName=index StackTrace: at System.Collections.ArrayList.get_Item(Int32 index) at System.Windows.Forms.DataGridViewSelectedRowCollection.get_Item(Int32 index) at VetoSmsServer.mainForm.removeEntryBt_Click(Object sender, EventArgs e ) 在 C:\WorkSpace\VetoSmsServer\VetoSmsServer\mainForm.cs:System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows 的第 310 行。 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 处 System.Windows.Forms.Control 处的 Forms.Button.OnMouseUp(MouseEventArgs 事件)。