none
DataGridView scroll error - minimum and maximum values

    Question


  • I have added a datagridview to my form.  The scrollbar property is set to Vertical.  If I add say 21 rows to the grid, and then try to use the down arrow key the following error is generated :-

    /EnvironmentVariables>
      <Exception Type="ArgumentOutOfRangeException">
        <Message>Value of '176' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.
    Parameter name: Value</Message>
        <Source>System.Windows.Forms</Source>
        <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.ScrollRowIntoView(Int32 columnIndex, Int32 rowIndex, Boolean committed, Boolean forCurrentCellChange)
       at System.Windows.Forms.DataGridView.ScrollIntoView(Int32 columnIndex, Int32 rowIndex, Boolean forCurrentCellChange)
       at System.Windows.Forms.DataGridView.ProcessDownKeyInternal(Keys keyData, Boolean&amp; moved)
       at System.Windows.Forms.DataGridView.ProcessDownKey(Keys keyData)
       at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
       at System.Windows.Forms.DataGridView.ProcessKeyPreview(Message&amp; m)
       at System.Windows.Forms.Control.ProcessKeyPreview(Message&amp; m)
       at System.Windows.Forms.Control.ProcessKeyMessage(Message&amp; m)
       at System.Windows.Forms.Control.WmKeyChar(Message&amp; m)
       at System.Windows.Forms.Control.WndProc(Message&amp; m)
       at System.Windows.Forms.TextBoxBase.WndProc(Message&amp; m)
       at System.Windows.Forms.TextBox.WndProc(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</StackTrace>
        <HelpLink />
        <TargetSite>set_Value</TargetSite>
      </Exception>

    Using the scroll bar, does not display all rows that have been added to the datagrid.

    • Moved by Zhi-Xin Ye Tuesday, July 28, 2009 2:09 PM (From:.NET Base Class Library)
    Wednesday, July 22, 2009 3:18 PM

All replies


  • Hello,

    <Message>Value of '176' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.
    Parameter name: Value</Message>

    What I get from this message is that, the datasource row count is smaller than 176. That's why vertical scroll does not work for that.
    However, if you send the code where this exception thrown, it can be more clear. From this point, detailed explanation can not be given, I guess. You may send some psudo or code itself on scrol method.
    • Proposed as answer by Jones Huang Thursday, April 07, 2011 8:36 AM
    Wednesday, July 22, 2009 6:47 PM
  • Thanks, but if I included PerfomLayout  it solved my problem.
    • Proposed as answer by Madhavan L Wednesday, August 12, 2009 7:39 AM
    Friday, July 31, 2009 8:02 AM
  •  Hi, I also get the same error in my application.  Where you included PerformLayout().  Kindly help me out

    Madhavan
    Wednesday, August 12, 2009 7:39 AM
  • hi

    you shoud add it after code adds Rows to your Datagridview

    like this

      for (int x = 0; x <20 ; x++)
          datagrid.Rows.Add((x).ToString(), "-----");


     datagrid.PerformLayout();

     

     

    • Proposed as answer by Alan Cossari Thursday, December 16, 2010 1:01 PM
    Sunday, July 11, 2010 7:08 AM
  • Many thank your answer
    Sunday, December 26, 2010 4:36 AM
  • I's Great Thank you so much
    Thursday, March 17, 2011 6:56 AM
  • hi

    you shoud add it after code adds Rows to your Datagridview

    like this

      for (int x = 0; x <20 ; x++)
          datagrid.Rows.Add((x).ToString(), "-----");


     datagrid.PerformLayout();

     

     


    Thanks very much!!
    • Proposed as answer by pthsoon Wednesday, November 02, 2011 7:55 AM
    Thursday, April 07, 2011 8:37 AM
  • Excelente, muchísimas gracias!
    Wednesday, July 27, 2011 5:23 PM