【发布时间】:2012-04-02 15:25:00
【问题描述】:
我有一个带有单个 DataGridView 的表单。 DGV 绑定到 DataTable 并在表单加载大约 32,000 条记录时填充。
如果用户在鼠标光标位于滚动条底部的向下箭头上时向下拖动滚动条并释放鼠标按钮,则会出现下面列出的异常。
如果在屏幕底部、状态栏下方、时钟上等其他任何位置释放鼠标按钮,则不会引发异常。然后您可以单击最后一条记录并向上滚动。
另外,如果您将滚动条一直向下拖动,在“安全”区域释放鼠标按钮,然后您可以再次滚动并释放向下箭头上的按钮,不会引发异常。
我在解决方案中的所有 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;
传递所有gridviews的基类格式。
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;
【问题讨论】:
-
我感觉我们需要查看您的一些代码才能做出诊断。
-
更新:我通过更改数据网格所在面板的大小并将其从表单边缘移开来掩盖了这个问题。 @詹姆士。我不确定要添加什么代码。我不认为问题出在 DGV 的代码中,它都是生成的。你想看什么代码?
-
添加了gridview构造和格式化代码。我有几个人看过这个,除了调整与表单相关的 Gridview 的格式之外,我们无法提出解决方案。这个问题违反了异常规则“滚动条的值在运行时无法通过用户交互达到其最大值”所以我不认为它在 c# 代码中,我可能错了,但到目前为止我们还没有能够弄清楚。
-
我也遇到了这个问题,或者类似的问题。
PerformLayout确实为我解决了这个问题。
标签: c# winforms datagridview scrollbar