gpt4 book ai didi

c# - DataGridView 滚动条抛出 ArgumentOutOfRange 异常

转载 作者:太空狗 更新时间:2023-10-30 00:55:19 26 4
gpt4 key购买 nike

我有一个带有单个 DataGridView 的表单。 DGV 绑定(bind)到 DataTable 并在表单加载约 32,000 条记录时填充。

如果用户向下拖动滚动条并在鼠标光标位于滚动条底部的向下箭头上时释放鼠标按钮,我将得到下面列出的异常。

如果在屏幕底部、状态栏下方、时钟等其他任何地方释放鼠标按钮,则不会引发异常。然后您可以单击最后一条记录并向上滚动。

此外,如果您一直向下拖动滚动条,在“安全”区域释放鼠标按钮,然后您可以再次滚动并释放向下箭头上的按钮,不会引发异常。

我在解决方案中的所有 DataGridView 都设置了相同的参数。我有其他具有相同或更多记录的 DGV,但他们不这样做。

关于 Scrollbar Max Value Microsoft 说:“最大值只能通过编程方式达到。滚动条的值无法通过运行时的用户交互达到其最大值。”

我没有在代码中操纵任何滚动条值。

我在任何地方都找不到关于此的任何信息。我希望有人能指出正确的方向来解决这个问题。

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:

GridView

    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都通过的Base Class Formatting。

        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;

最佳答案

关于c# - DataGridView 滚动条抛出 ArgumentOutOfRange 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9979126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com