我有一个单一的DataGridView的形式。 DGV绑定到DataTable并在表单加载大约32,000条记录时填充。DataGridView滚动条抛出ArgumentOutOfRange异常
如果用户拖动滚动条并释放鼠标按钮,当鼠标光标位于滚动条底部的向下箭头时,我将得到下面列出的例外。
如果在屏幕底部等任何其他位置释放鼠标按钮,则在状态栏中的时钟上不会抛出异常。然后,您可以点击最后一个记录并向上滚动。另外,如果您一直向下拖动滚动条,请在“安全”区域释放鼠标按钮,然后您可以再次滚动并释放向下箭头上的按钮,并且不会抛出异常。
解决方案中的所有DataGridView都设置了相同的参数。我有其他DGV的相同或更多的记录,他们不这样做。
关于滚动条最大值微软表示:“最大值只能以编程方式达到,通过用户在运行时的交互,滚动条的值不能达到最大值。
我没有操纵代码中的任何滚动条值。
我找不到任何关于此的任何内容。我希望有人能指出我正确的方向来解决这个问题。
System.ArgumentOutOfRangeException was unhandled Message=Value of
'2612103' is not valid for 'Value'. 'Value' should be between
'minimum' and 'maximum'. Parameter name: Value
Source=System.Windows.Forms ParamName=Value StackTrace:
at System.Windows.Forms.ScrollBar.set_Value(Int32 value)
at System.Windows.Forms.ScrollBar.DoScroll(ScrollEventType type)
at System.Windows.Forms.ScrollBar.WmReflectScroll(Message& m)
at System.Windows.Forms.ScrollBar.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 aram, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,
Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
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.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollBar.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 VWBSMS.Program.Main() in C:\Documents and Settings\courtp\My Documents\Development\C++_DLL_Projects\VWBSMS\VWBSMS\MDIForms\Program.cs:line
21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
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() InnerException:
网格视图
this.dtGrid.AllowUserToAddRows = false;
this.dtGrid.AllowUserToDeleteRows = false;
this.dtGrid.AutoGenerateColumns = false;
this.dtGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dtGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.idCol,
this.lineColumn,
this.lineCol,
this.eqpCol,
this.minColumn,
this.eqptColumn,
this.rpNameCol,
this.malCol,
this.solutionColumn,
this.ltColumn,
this.faultColumn,
this.originatorCol,
this.dateCol,
this.timeDownCol,
this.dateUpCol,
this.timeUpCol,
this.T2ID,
this.T1ID,
this.threeCodeCol,
this.respCol});
this.dtGrid.ContextMenuStrip = this.gvContextMenut;
this.dtGrid.DataSource = this.dTMPNewBindingSource;
this.dtGrid.Dock = System.Windows.Forms.DockStyle.Fill;
this.dtGrid.Location = new System.Drawing.Point(0, 0);
this.dtGrid.Name = "dtGrid";
this.dtGrid.ReadOnly = true;
this.dtGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dtGrid.Size = new System.Drawing.Size(980, 360);
this.dtGrid.TabIndex = 115;
基类格式,所有的GridView的传递。
dgvA.AllowUserToAddRows = false;
dgvA.AllowUserToDeleteRows = false;
dgvA.AllowUserToOrderColumns = true;
dgvA.AllowUserToResizeColumns = true;
dgvA.AllowUserToResizeRows = false;
dgvA.RightToLeft = System.Windows.Forms.RightToLeft.No;
dgvA.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
// Main Grid Settings
dgvA.BackgroundColor = SystemColors.Control;
dgvA.BorderStyle = BorderStyle.None;
dgvA.GridColor = SystemColors.ActiveBorder;
// ************* Column Headers **********************
// General Settings
dgvA.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
dgvA.ColumnHeadersHeight = 20; // Based on a Tahoma font of 9
dgvA.ColumnHeadersVisible = true;
dgvA.Cursor = Cursors.Default;
dgvA.EnableHeadersVisualStyles = true;
// Column Headers Default Cell Style
dgvA.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvA.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Control;
dgvA.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.WindowText;
dgvA.ColumnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.MenuHighlight;
dgvA.ColumnHeadersDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
// ********************** ROWS ************************
// Alternating Rows Default Cell Style
dgvA.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.Info;
dgvA.AlternatingRowsDefaultCellStyle.ForeColor = SystemColors.WindowText;
// Row Headers
dgvA.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
dgvA.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
dgvA.RowHeadersDefaultCellStyle.BackColor = SystemColors.Control;
dgvA.RowHeadersDefaultCellStyle.ForeColor = SystemColors.WindowText;
dgvA.RowHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
dgvA.RowHeadersDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
dgvA.RowHeadersVisible = false;
// ************* Default Cell Style ******************
dgvA.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvA.DefaultCellStyle.BackColor = SystemColors.Window;
dgvA.DefaultCellStyle.ForeColor = SystemColors.WindowText;
dgvA.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
dgvA.DefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
dgvA.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
被设置在这里的构造
base.gridThemeSet(dtGrid);
DataGridViewCellStyle myStyle = new DataGridViewCellStyle();
myStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
malCol.DefaultCellStyle = myStyle;
我有一种感觉,我们需要查看一些代码来进行诊断。 – deutschZuid 2012-04-03 02:13:02
更新:我通过更改数据网格所在的面板的大小并将其从表单的边缘移开来掩盖了问题。 @詹姆士。我不知道要添加什么代码。我不认为问题出现在DGV的代码中,其全部生成。你想看什么代码? – Kassabba 2012-04-03 11:32:19
添加了gridview构造和格式化代码。我有几个人看这个,我们不能提出一个解决方案,而不是调整格式的格式相关的形式。这个问题违反了例外规则“滚动条在运行时不能达到通过用户交互其最大价值的价值”,所以我不认为它在C#代码,我可能是错的,但由于我们到现在还没有能够弄清楚。 – Kassabba 2012-04-11 12:04:52