我有一個贏的窗體上的按鈕,其中刪除網格視圖上的行。沒有選擇的按下網格視圖的按鈕
numberSettingTable.SelectedRows[0]
問題是當我按下按鈕沒有行選擇它發送null,在Java -1是返回它告訴沒有行被選中。那麼我怎樣才能在c#中實現相同?
我已經試過if語句
numberSettingTable.SelectedRows[0] != null
但它沒有工作。
以下是錯誤的詳細信息。
System.ArgumentOutOfRangeException未處理 Message = Index超出範圍。必須是非負數且小於集合的大小。 參數名稱:索引 源= mscorlib程序 PARAMNAME =指數 堆棧跟蹤: 在System.Collections.ArrayList.get_Item(的Int32指數) 在System.Windows.Forms.DataGridViewSelectedRowCollection.get_Item(的Int32指數) 在VetoSmsServer.mainForm。 C:\ WorkSpace \ VetoSmsServer \ VetoSmsServer \ mainForm.cs中的removeEntryBt_Click(Object sender,EventArgs e):行310 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick (EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message & m,MouseButtons button,Int32 clicks) 在System.Windows.Forms.Control.WndProc(消息&米) 在System.Windows.Forms.ButtonBase.WndProc(消息&米) 在System.Windows.Forms.Button.WndProc(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&米) 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND,的Int32 msg,IntPtr wparam,IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG & msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.For ms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at VetoSmsServer.Program.Main()in C:\ WorkSpace \ VetoSmsServer \ VetoSmsServer \ Program.cs:line 18 at System .AppDomain._nExecuteAssembly(RuntimeAssembly組件,字串[] args) 在System.AppDomain.ExecuteAssembly(字符串assemblyFile,證據assemblySecurity,字串[] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在SY在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回調,對象狀態,布爾ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object狀態) 在System.Threading.ThreadHelper。的ThreadStart() 的InnerException:
已經嘗試了上述 – greatmajestics