2010-12-20 9 views
7

は、私がアプリケーション例外のWindowsフォームアプリケーションの例外

at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) 
    at System.Windows.Forms.CurrencyManager.get_Current() 
    at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e) 
    at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred) 
    at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) 
    at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown) 
    at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e) 
    at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e) 
    at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.DataGridView.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at 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.Forms.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 MedForms.Program.Main() in F:\Projects\Vstu\MedForms\MedForms\Program.cs:line 18 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

私はDataGridViewのをクリックしようとするたびに取得します。

Iは{ "インデックスが-1の値を持っていない。"}エラーメッセージ

を取得 (SystemIndexOutOfaRange例外)。

Application.Run(new MainForm()); 

と私はそれをデバッグすることはできませんよ。私はこのような問題を引き起こす可能性があり、それをどのようにデバッグすることができるのかを教えてください。

+1

例外メッセージとは何ですか?今あなたの最大の手がかりは、 'CurrencyManager'への参照です。通貨で行っているグリッドは何ですか?具体的には、クリックしている行のデータに何か問題がありますか? – David

+0

Davidと並んで、完全なスタックトレースは何ですか?これは重要な情報がありません – NotMe

+0

完全なスタックトレースです。他に何もありません...私はollyエラーメッセージを追加することができます{"インデックス-1に値がありません"}(SystemIndexOutOfaRange例外)。私はそれを質問に加えました。 – Anton

答えて

20

私はあなたのDataGridViewに最初は空であるリスト(またはリスト変更されたイベントを生成しない他の種類のコレクション)をバインドしてから、このリストに項目を追加したと推測しています。

あなたはグリッド上正しく表示がされますが、行をクリックすると、この例外が発生します追加項目。これは、基になるCurrencyManagerが-1のオフセットとして現在の行の位置を報告するためです。リストはグリッドへの変更を報告しないため、この方法はそのままです。

グリッドにリストをバインドする必要があります。グリッドには、最初に項目がある場合はバインドするか、追加するときは再バインドする必要があります。

私の答えはthisです。これは本質的に同じ問題です。アンディのアドバイスに従い

+0

はい、私はバインディングリストです。バインドする前にリストが空であるかどうかを調べようとします。 – Anton

+0

ありがとう、本当に助けて! – Anton

+1

@Anton:私は良い推測をしました:) – Andy

0

は私が

private BindingList<Employee> Employees { get; set; } = new BindingList<Employee>(); _employeesGridView.DataSource = Employees;

private List<Employee> Employees { get; set; } = new List<Employee>(); _employeesGridView.DataSource = Employees;

を置換し、問題が姿を消しました。

関連する問題