2010-12-20 19 views
7

मैं आवेदन अपवादविंडोज प्रपत्र आवेदन अपवाद

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 पर क्लिक करने की कोशिश मिलता है।

मैं त्रुटि संदेश

{ "सूचकांक -1 एक मूल्य नहीं है।"} (SystemIndexOutOfaRange अपवाद) मिलता है।

पंक्ति

Application.Run(new MainForm()); 

पर

और मैं इसे डिबग करने में सक्षम नहीं हूँ। कृपया मुझे यह जानने में सहायता करें कि ऐसी समस्या का कारण क्या हो सकता है और मैं इसे कैसे डिबग कर सकता हूं?

+1

अपवाद संदेश क्या है? आपका सबसे बड़ा सुराग अभी 'CurrencyManager' का संदर्भ है। मुद्रा के साथ ग्रिड क्या कर रहा है? विशेष रूप से, क्या आप जिस पंक्ति पर क्लिक कर रहे हैं उस डेटा के साथ कुछ भी गलत है? – David

+0

दाऊद के साथ साथ, पूर्ण स्टैक ट्रेस क्या है? इसमें महत्वपूर्ण जानकारी गुम है – NotMe

+0

यह पूर्ण स्टैक ट्रेस है। और कुछ नहीं है ... मैं ऑली में जोड़ सकते हैं कि त्रुटि संदेश (SystemIndexOutOfaRange अपवाद) { "सूचकांक -1 एक मूल्य नहीं है।"} है। मैंने इसे प्रश्न में जोड़ा। – Anton

उत्तर

20

मुझे लगता है कि आपने एक सूची को बाध्य किया है जो प्रारंभ में खाली है, (या अन्य प्रकार का संग्रह जो सूची बदलती घटनाओं को उत्पन्न नहीं करता है) आपके DataGridView पर, और फिर इस सूची में आइटम जोड़े गए।

आइटम आप करेंगे प्रदर्शन अपने ग्रिड पर सही ढंग से जोड़ने के लिए, लेकिन एक पंक्ति पर क्लिक इस अपवाद का कारण होगा। इसका कारण यह है अंतर्निहित CurrencyManager एक -1 की भरपाई के रूप में अपनी वर्तमान पंक्ति स्थिति रिपोर्टिंग की जाएगी। यह इस तरह से रहेगा क्योंकि सूची ग्रिड में परिवर्तन की रिपोर्ट नहीं करती है।

आप केवल ग्रिड के लिए अपनी सूची के लिए बाध्य करना चाहिए अगर यह उस में कुछ वस्तुओं के साथ शुरू करते हैं, या rebind जब आप उन्हें जोड़ने के लिए है।

this सवाल है, जो मूलतः एक ही समस्या है करने के लिए भी मेरा उत्तर देखें।

+0

हां, मैं बाध्यकारी सूची हूं। मैं यह जांचने की कोशिश करूंगा कि बाध्यकारी से पहले सूची खाली है या नहीं। – Anton

+0

धन्यवाद, यह वास्तव में मदद करता है! – Anton

+1

@ एंटन: मैंने एक अच्छा अनुमान लगाया :) – 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;

प्रतिस्थापित और समस्या गायब हो गया।

संबंधित मुद्दे