打开一个窗体后,不做任何操作,点击右上角的红叉来关闭,出异常“索引超出范围。必须为非负值并小于集合大小。”。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing); //异常出现在这句上!
}自已试了一下,发现只要点击过tabControl的tabPage2就不会出现上述情况。(窗体初始显示的是tabPage1)
tabPage2上面有很多东西:button、groupBox、label、radioButton、pictureBox、checkBox、dataGridView。我大概错在哪了?请给我一个方向,谢谢!
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing); //异常出现在这句上!
}自已试了一下,发现只要点击过tabControl的tabPage2就不会出现上述情况。(窗体初始显示的是tabPage1)
tabPage2上面有很多东西:button、groupBox、label、radioButton、pictureBox、checkBox、dataGridView。我大概错在哪了?请给我一个方向,谢谢!
解决方案 »
- 如何将时间表示为utc时间,并求值。
- C#抓取动态网页数据 很有挑战哦
- windows服务cmd程序拒绝访问
- 请问高手:这个图片切换效果为什么在html文件中能显示正常,在c#中就不正常了呢?
- like '%[2008]%'报错,说不可识别字符串,怎么解决阿
- 一道测试题
- 最最基础的取内存地址的问题,急急急在线等。。。。。。。。。。。。。。。。。。
- 大哥帮忙,我想在datagrid中能够精确的定位加入新行 ?
- 大家都来测-- error cs0234:类型或命名空间名称“Xml”在类或命名空间“System”中不存在.
- 怪问?
- MonthCalendar控件可不可以让它折叠起来
- Treeview的After_Select事件,初始选择问题
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
//DataGridViewColumn col13 = new DataGridViewButtonColumn();//'建立一个新的列
//col13.DisplayIndex = dataGridView2.Columns[13].DisplayIndex;//并设置其属性与要改变的列相同
//col13.DataPropertyName = dataGridView2.Columns[13].DataPropertyName;
//col13.HeaderText = dataGridView2.Columns[13].HeaderText;
//col13.Name = dataGridView2.Columns[13].Name;
//dataGridView2.Columns.RemoveAt(13);//'除去要改变的列
//dataGridView2.Columns.Insert(13, col13);//'添加新的列
因为tabPage2中有一个dataGridView2;其中的Columns[13]想是DataGridViewButtonColumn样式的,所以写了这段代码。现在是没有这段代码是不会出问题;
有这段代码,但打开窗体后,点击出tabPage2后关闭窗体也不会出现问题。
有这段代码,且打开窗体后,立即关闭窗体会出现问题。(打开窗体默认是tabPage1显示)
老大,我一直没敢回你的话。因为StackTrace我不会用,呵呵。
看了你回贴后,特意跑到msdn上想学一下StackTrace的用法,学的晕乎乎的,没学明白。
惭愧,惭愧,没有系统的学习就是不行啊!
你调试时出现异常的时候,可以在编译器里看到异常的详细信息,里面找一下StackTrace就能看到。或者你catch了异常后MessageBox.Show(e.StackTrace)看看
在 System.Collections.ArrayList.get_Item(Int32 index)
在 System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)
在 System.Windows.Forms.DataGridView.FlushDisplayedChanged()
在 System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)
在 System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)
在 System.Windows.Forms.DataGridView.OnColumnCollectionChanged_PreNotification(CollectionChangeEventArgs ccea)
在 System.Windows.Forms.DataGridViewColumnCollection.OnCollectionChanged(CollectionChangeEventArgs ccea, Boolean changeIsInsertion, Point newCurrentCell)
在 System.Windows.Forms.DataGridViewColumnCollection.Clear()
在 System.Windows.Forms.DataGridView.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.Windows.Forms.TabControl.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
在 System.Windows.Forms.Form.Dispose(Boolean disposing)
在 HB_Class.HBFormA.Dispose(Boolean disposing) 位置 C:\Users\LIUBO\Desktop\HB_C#_A018.5\HB_ClassLibrary\HBFormA.Designer.cs:行号 20
在 HB_Class.HBFormA_X2_A.Dispose(Boolean disposing) 位置 C:\Users\LIUBO\Desktop\HB_C#_A018.5\HB_ClassLibrary\HBFormA_X2_A.Designer.cs:行号 20
在 HB_WindowsFormsApplication.Form进货单.Dispose(Boolean disposing) 位置 C:\Users\LIUBO\Desktop\HB_C#_A018.5\HB_WindowsFormsApplication\Form进货单.Designer.cs:行号 20
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Form.WmClose(Message& m)
在 System.Windows.Forms.Form.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, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
在 System.Windows.Forms.Form.DefWndProc(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmSysCommand(Message& m)
在 System.Windows.Forms.Form.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, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
在 System.Windows.Forms.Form.DefWndProc(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmNcButtonDown(Message& m)
在 System.Windows.Forms.Form.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, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 HB_WindowsFormsApplication.Program.Main() 位置 C:\Users\LIUBO\Desktop\HB_C#_A018.5\HB_WindowsFormsApplication\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
在 System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)看这两行,有可能是DGV 的 数据绑定造成的。
//DataGridViewColumn col13 = new DataGridViewButtonColumn();//'建立一个新的列
//col13.DisplayIndex = dataGridView2.Columns[13].DisplayIndex;//并设置其属性与要改变的列相同
//col13.DataPropertyName = dataGridView2.Columns[13].DataPropertyName;
//col13.HeaderText = dataGridView2.Columns[13].HeaderText;
//col13.Name = dataGridView2.Columns[13].Name;
//dataGridView2.Columns.RemoveAt(13);//'除去要改变的列
//dataGridView2.Columns.Insert(13, col13);//'添加新的列
这段代码是写在哪里的?
写在窗体的Shown里面,试过放在Load里面,也不行。