none
Value of '11608' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name:Value' RRS feed

  • Question

  • Error occur when display data on the DataGridView of the UserControl like following.

    Value of '11608' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name:Value'

    Here is the code snippet.(gridConversationMessages is DataGridView)

    if (keepRowIndex >= 0)
       gridConversationMessages.FirstDisplayedScrollingRowIndex = keepRowIndex;   // Error occur !

    This error doesn't occur when keepRowIndex is small value, for example, when it is 46.

    However error occur when it is bigger value, for example, when it is 100.

    And keepRowIndex is 100, not 11608, when error occur. I don't know why the error message says value is 11608.

    According to the explanation of MSDN, this exception handling occurs from DataGridView's FirstDisplayedScrollingRowIndex when ..... Here is the comment from MSDN.

    ArgumentOutOfRangeException
    The specified value when setting this property is less than 0 or greater than the number of rows in the control minus 1.

    If I check the both value, lvalue is always smaller 1 than rvalue like following.

         gridConversationMessages.Rows.Count = 47, keepRowIndex = 46     // No error
         gridConversationMessages.Rows.Count = 101, keepRowIndex = 100   // Error occur

    I found that error occur when keepRowIndex is greater than or equal to 97.

    Can anybody give me any idea about this error?


     




    • Edited by Jeff0803 Sunday, February 16, 2020 2:27 AM
    Saturday, February 15, 2020 9:54 PM

All replies

  • when you change your code to:
    if (keepRowIndex >= 0
       && keepRowIndex < gridConversationMessages.Rows.Count)
       gridConversationMessages.FirstDisplayedScrollingRowIndex = keepRowIndex;   // Error occur !
    does it still throw?
    Opening the System.Windows.Forms.dll in a disassembler one can see that the setter only throws an ArgumentOutOfRangeException when:
    public int FirstDisplayedScrollingRowIndex
    {
    	set
    	{
    		if (value < 0 || value >= this.Rows.Count)
    		{
    			throw new ArgumentOutOfRangeException("value");
    		}
    so either you are indeed calling with a different value then you think,
    or the exception is coming from one of the private methods called by FirstDisplayedScrollingRowIndex.
    Make sure to look at the call stack of the exception.


    • Edited by EckiS Sunday, February 16, 2020 11:52 AM
    Sunday, February 16, 2020 11:51 AM
  • I added && keepRowIndex < gridConversationMessages.Rows.Count but still error occur.

    Here is the detail.

    System.ArgumentOutOfRangeException
      HResult=0x80131502
      Message=Value of '11608' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.
    Parameter name: Value
      Source=System.Windows.Forms
      StackTrace:
       at System.Windows.Forms.ScrollBar.set_Value(Int32 value)
       at System.Windows.Forms.DataGridView.ScrollRows(Int32 rowCount, Int32 deltaY, ScrollEventType scrollEventType)
       at System.Windows.Forms.DataGridView.ScrollRowsByCount(Int32 rows, ScrollEventType scrollEventType)
       at System.Windows.Forms.DataGridView.set_FirstDisplayedScrollingRowIndex(Int32 value)
       at Denttio.Message.ConversationCtrl.RefreshData() in C:\WorkDir\DenttioMessageApplication\TextingControl\ConversationCtrl.cs:line 275
       at Denttio.Message.ConversationHistoryForm.ShowConversationHistory(Int32 mode) in C:\WorkDir\DenttioMessageApplication\CDMMsgView\ConversationHistoryForm.cs:line 265
       at Denttio.Message.ConversationHistoryForm.NotifyPatientID(Double patient_id, String patientname, String cell_phone) in C:\WorkDir\DenttioMessageApplication\CDMMsgView\ConversationHistoryForm.cs:line 78
       at Denttio.Message.ConversationHistoryForm.bttnSelectPatient_Click(Object sender, EventArgs e) in C:\WorkDir\DenttioMessageApplication\CDMMsgView\ConversationHistoryForm.cs:line 135
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.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.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.Form.ShowDialog()
       at Denttio.Message.MainForm.toolStripButtonConversationHistory_Click(Object sender, EventArgs e) in C:\WorkDir\DenttioMessageApplication\CDMMsgView\MainForm.cs:line 376
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.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 Denttio.Message.Program.Main() in C:\WorkDir\DenttioMessageApplication\CDMMsgView\Program.cs:line 23

    If I add try~catch to get the value when error occur like following,

    if (keepRowIndex >= 0 && keepRowIndex < gridConversationMessages.Rows.Count)
    {
        try
        {
            gridConversationMessages.FirstDisplayedScrollingRowIndex = keepRowIndex;
        }
        catch
        {
            MessageBox.Show("gridConversationMessages.FirstDisplayedScrollingRowIndex = " + gridConversationMessages.FirstDisplayedScrollingRowIndex.ToString() + Environment.NewLine + 
                            "keepRowIndex = " + keepRowIndex.ToString());
        }
    }
    Both value is like following.
     

    Error occurs not from FirstDisplayedScrollingRowIndex property but from System.Windows.Forms.ScrollBar.set_Value(Int32 value) as you see the detail.

    • Edited by Jeff0803 Sunday, February 16, 2020 7:37 PM
    Sunday, February 16, 2020 7:30 PM
  • Did you see that the error is coming from your ScrollBar, not from your DataGridView?  My guess is that you set your ScrollBar limits arbitrarily to 0 and 100, and you're not updating them based on your view contents.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Sunday, February 16, 2020 7:35 PM
  • My form(ChattingSession) doesn't have scrollbar.

    It has only one control(ConversationCtrl) which is inherited from UserControl.

    ConversationCtrl consists of label, datagridview, textbox and button.

    Scrollbar is provided by DataGridView and I don't use separate scrollbar control.


    • Edited by Jeff0803 Sunday, February 16, 2020 9:43 PM
    Sunday, February 16, 2020 9:36 PM
  • you could look at the workarounds mentioned here:
    DataGridView scrollbar throwing ArgumentOutOfRange exception

    is this in the current .NET Framework version (4.8)?
    Sunday, February 16, 2020 9:59 PM
  • It's .NET Framework 4.6.1.

    Monday, February 17, 2020 1:30 AM
  • Hi jeff,

    Thank you for posting here.

    Can you tell me how to get keepRowIndex?

    Or give us a piece of code that can reproduce this problem, which can help us find and solve this problem faster.

    Best Regards,

    Timon



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 17, 2020 10:03 AM