我的表单上有一个datagridview。
I have a datagridview on my form.
datagridview将AutoResizeColumn设置为Fill,一切正常。
the datagridview had the AutoResizeColumn set to Fill and everything worked fine.
我现在将其更改为All,当我点击colum标题时,我得到System.NullReferenceException。
I now changed it to All and when I click on the colum header a few time I get System.NullReferenceException.
我点击了一行时发生了一个事件,我知道那里没有发生异常。
I have one event that occurs when a row is clicked and I know the exception is not happening in there.
下面是错误的描述(很遗憾,它太长了)。任何意见,将不胜感激。
Below is a description of the error (sorry that it is so long). Any advice would be appreciated.
无论如何,我是否可以捕获此错误并阻止它终止我的应用程序?
Is there anyway that I could just catch this error and prevent it from terminating my application?
System.NullReferenceException未处理 Message ="对象引用未设置为对象的实例。" Source =" System.Windows.Forms" StackTrace: System.Windows.Forms.DataGridView.ComputeVisibleColumns() at System.Windows.Forms.DataGridView.LayoutScrollBars() at System .Windows.Forms.DataGridView.ComputeLayout() at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut,Boolean computeVisibleRows,Boolean invalidInAdjustFillingColumns,Boolean repositionEditingControl) at System.Windows.Forms.DataGridView.OnColumnWidthChanged( DataGridViewColumnEventArgs e) System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand dataGridViewBand) System.Windows.Forms.DataGridView.AutoResizeColumnInternal(Int32 columnIndex,DataGridViewAutoSizeColumnCriteriaInternal autoSizeCol umnCriteriaInternal,Boolean fixedHeight)在System.Windows上的System.Windows.Forms.DataGridView.AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaFilter,Boolean fixedHeight) System.Windows.Forms.DataGridView.OnAddedRow_PostNotification(Int32 rowIndex) Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca,Int32 rowIndex,Int32 rowCount,DataGridViewRow dataGridViewRow,Boolean changeIsDeletion,Boolean changeIsInsertion,Boolean recreateNewRow,Point newCurrentCell) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e,Int32 rowIndex, Int32 rowCount) System.Windows.Fo上的System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow) System.Windows.Fo的System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)在System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)的System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender,ListChangedEventArgs e)中的rms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender,ListChangedEventArgs e) System.Data.DataView.UnListChanged(ListChangedEventArgs e) System.Data.DataView.UpdateIndex(Boolean force,布尔fireEvent)在System.Data.Data.Data.SupIndex2上的System.Data.DataView.UpdateIndex(布尔强制) System.Data上的System.Data.DataView.SetIndex2(String newSort,DataViewRowState newRowStates,DataExpression newRowFilter,Boolean fireEvent)。 System.Data.DataView.set_Sort(String val)中的DataView.SetIndex(String newSort,DataViewRowState newRowStates,DataExpression newRowFilter) ue)在System.Data.DataView.System.ComponentModel.IBindingList.ApplySort(PropertyDescriptor属性,ListSortDirection方向) System.Windows.Forms.DataGridView.DataGridViewDataConnection.Sort(DataGridViewColumn dataGridViewColumn,ListSortDirection direction)在System.Windows.Fors上的System.Windows.Forms.DataGridView.SortInternal(IComparer比较器,DataGridViewColumn dataGridViewColumn,ListSortDirection方向) System.Windows.Forms上的System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn,ListSortDirection方向) System.WindView.OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) System.Windows.Fornd.DataMridView.OnMouseClick(MouseEventArgs e) System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons按钮,Int32单击)在System.Windows.Forms.Control.WndProc(Message& m) System.Windows.Forms.DataGridView.WndProc(Message& m)在System。 Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd在System.Windows.Forns.Forms.Forms.Forms.UnsafeNativeMethods的System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)中,Int32 msg,IntPtr wparam,IntPtr lparam)。在System.Windows.Forms.Application.ThreadContext.RunMessageLoop的System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)中的IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) ( Int32原因,ApplicationContext上下文)在System.Windows.Forms.Application.Run(Form mainForm)中的GuardianConfig.Program.Main()在C:\ vsswork \ Guardard \ GuardianConfig \ GuardianConfig \\ GuardardConfig \Program.cs:第18行 System.AppDomain.nExecuteAssembly(程序集,String [] args) System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)<在System.Threading.Thread上的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart()
System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.DataGridView.ComputeVisibleColumns() at System.Windows.Forms.DataGridView.LayoutScrollBars() at System.Windows.Forms.DataGridView.ComputeLayout() at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl) at System.Windows.Forms.DataGridView.OnColumnWidthChanged(DataGridViewColumnEventArgs e) at System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand dataGridViewBand) at System.Windows.Forms.DataGridView.AutoResizeColumnInternal(Int32 columnIndex, DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaInternal, Boolean fixedHeight) at System.Windows.Forms.DataGridView.AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaFilter, Boolean fixedHeight) at System.Windows.Forms.DataGridView.OnAddedRow_PostNotification(Int32 rowIndex) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount) at System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow) at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e) at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e) at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e) at System.Data.DataView.OnListChanged(ListChangedEventArgs e) at System.Data.DataView.UpdateIndex(Boolean force, Boolean fireEvent) at System.Data.DataView.UpdateIndex(Boolean force) at System.Data.DataView.SetIndex2(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter, Boolean fireEvent) at System.Data.DataView.SetIndex(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter) at System.Data.DataView.set_Sort(String value) at System.Data.DataView.System.ComponentModel.IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.SortInternal(IComparer comparer, DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) at System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(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(Int32 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 GuardianConfig.Program.Main() in C:\vsswork\Guardian\GuardianConfig\GuardianConfig\GuardianConfig\Program.cs:line 18 at System.AppDomain.nExecuteAssembly(Assembly 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) at System.Threading.ThreadHelper.ThreadStart()
推荐答案
我遇到了完全相同的问题。在我的场景中,AutoSizeColumnsMode设置为'DisplayedCell'。当我单击列标题时,我得到一个NullReferenceException。堆栈跟踪如下所示。
I have experienced exactly the same problem. In my scenario, the AutoSizeColumnsMode is set to 'DisplayedCell'. When I click on a column header, I get a NullReferenceException. Stack trace is shown below.
这是DataGridView控件中的错误吗?有没有人知道一个解决方法?
Is this a bug in the DataGridView control? Does anyone know a workaround?
在System.Windows.Forms.DataGridView.ComputeVisibleColumns() at System.Windows.Forms.DataGridView.LayoutScrollBars() at System.Windows.Forms.DataGridView.ComputeLayout() at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut,Boolean computeVisibleRows,Boolean invalidInAdjustFillingColumns,Boolean repositionEditingControl) System.Windows.Forms.DataGridView.OnColumnWidthChanged(DataGridViewColumnEventArgs e) System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand dataGridViewBand) System.Windows.Forms.DataGridView.AutoResizeColumnInternal( Int32 columnIndex,DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaInternal,Boolean fixedHeight) at System.Windows.Forms.DataGridView.AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaFilter, System.Windows.Forms.DataGridView.OnAddedRow_PostNotification(Int32 rowIndex) System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca,Int32 rowIndex,Int32 rowCount,DataGridViewRow dataGridViewRow,Boolean changeIsDeletion,Boolean changeIsInsertion,Boolean recreateNewRow,Point newCurrentCell) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e,Int32 rowIndex,int32 rowCount) at System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow) at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView) System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged( System.Windows中的Object sender,ListChangedEventArgs e) .Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e) System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender,ListChangedEventArgs e) System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)在System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender,ListChangedEventArgs e) System.Data.DataView.OnListChanged(ListChangedEventArgs e) System.Data.DataView.UpdateIndex(Boolean force,Boolean fireEvent) System.Data.Data.Data.S.Index2中的System.Data.DataView.UpdateIndex(布尔强制) System.Data.DataView.SetIndex中的System.Data.DataView.SetIndex2(String newSort,DataViewRowState newRowStates,DataExpression newRowFilter,Boolean fireEvent) (String newSort,DataViewRowState newRowStates,DataExpression newRowFilter) at System.Data.DataView.set_Sort(String value) at System.Data.DataView.System.ComponentModel.IBindingList.ApplySort(PropertyDescriptor property,ListSortDirection dire ction)在System.Windows.Forms.BindingSource.ApplySort(PropertyDescriptor属性,ListSortDirection sort) System.Windows.Forms.DataGridView.DataGridViewDataConnection.Sort(DataGridViewColumn dataGridViewColumn,ListSortDirection direction)在System。 Windows.Forms.DataGridView.SortInternal(IComparer比较器,DataGridViewColumn dataGridViewColumn,ListSortDirection方向) System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn,ListSortDirection方向) System.Windows.Forms.DataGridView.OnColumnHeaderMouseClick System.Windows.Forms.Control.WmMouseUp上的System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e)的(DataGridViewCellMouseEventArgs e)(消息& m,MouseButtons按钮,Int32单击)在System.Windows.Forms.Control.WndProc(Message& m) System.Windows.Forms.DataGridView.WndProc(Message& m)在System。 Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd在System.Windows.Forns.Forms.Forms.Forms.UnsafeNativeMethods的System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)中,Int32 msg,IntPtr wparam,IntPtr lparam)。在System.Windows.Forms.Application.ThreadContext.RunMessageLoop的System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)中的IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) (Int32原因,ApplicationContext上下文)在System.Windows.Form s.Application.Run(Form mainForm)
at System.Windows.Forms.DataGridView.ComputeVisibleColumns() at System.Windows.Forms.DataGridView.LayoutScrollBars() at System.Windows.Forms.DataGridView.ComputeLayout() at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl) at System.Windows.Forms.DataGridView.OnColumnWidthChanged(DataGridViewColumnEventArgs e) at System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand dataGridViewBand) at System.Windows.Forms.DataGridView.AutoResizeColumnInternal(Int32 columnIndex, DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaInternal, Boolean fixedHeight) at System.Windows.Forms.DataGridView.AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal autoSizeColumnCriteriaFilter, Boolean fixedHeight) at System.Windows.Forms.DataGridView.OnAddedRow_PostNotification(Int32 rowIndex) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell) at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount) at System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow) at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e) at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e) at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e) at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e) at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e) at System.Data.DataView.OnListChanged(ListChangedEventArgs e) at System.Data.DataView.UpdateIndex(Boolean force, Boolean fireEvent) at System.Data.DataView.UpdateIndex(Boolean force) at System.Data.DataView.SetIndex2(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter, Boolean fireEvent) at System.Data.DataView.SetIndex(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter) at System.Data.DataView.set_Sort(String value) at System.Data.DataView.System.ComponentModel.IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction) at System.Windows.Forms.BindingSource.ApplySort(PropertyDescriptor property, ListSortDirection sort) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.SortInternal(IComparer comparer, DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction) at System.Windows.Forms.DataGridView.OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) at System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(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(Int32 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)
更多推荐
单击列标题时出现System.NullReferenceException
发布评论