datagridview throws exception when navigating with arrow keys


  • hi, i am using some datagridviews in my app. i add rows to them with the rows.add() method, something like whatever.Rows.add(new string[] { sql_result["SOME_COLUMN"].toString() (...) etc

    so far it has no problem; the problem was that even tough the search results where many, it only showed a few of them.

    i made some tries and found out all the search results were added, but the vertical scroll bar was not resized properly, so i could not navigate trough all the rows added. i had to select any of the added rows, and then scroll down with the down arrow key. so far, weird, bad api for components but the app did not crash (so far).

    i am using three datagridviews, i am using them all more or less the same, but in one of those, when i scroll down with the down arrow key, it gives an exception. it is not a data error, since the data has already been added, and if that was the case, it would throw the exception in the moment of adding data, not when scrolling to see it.

    most problems would be solved if the side scroll bar of the datagridview would resize properly so i could scroll through all the arrows (is there a method for that?), but since it was not done as it should have been, any pointers why is it crashing my app when i browse the datagridview with the arrow keys? once again, it is not a data problem, there is no problem when it shows only the very same arrows where it crashes, whith the same data, and it goves no error when adding data (only when selecting them with the down arrow, also, it is not the last arrow, there should be a lot more below that, but i can not reach them this way)

    ------------------the next one is the message given, not thrown by my code but the datagridview.

    No se controló System.ArgumentOutOfRangeException
      Message="Value of '154' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.\r\nParameter name: Value"
           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& moved)
           at System.Windows.Forms.DataGridView.ProcessDownKey(Keys keyData)
           at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
           at System.Windows.Forms.DataGridView.OnKeyDown(KeyEventArgs e)
           at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
           at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
           at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
           at System.Windows.Forms.Control.WmKeyChar(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.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 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 WindowsApplication1.Program.Main() in C:\Documents and Settings\Jairo\My Documents\Visual Studio 2005\Projects\imprimir_etiquetas v3\imprimir_etiquetas\Program.cs:line 17
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    Tuesday, February 24, 2009 12:42 AM


  • forget it, now i am doing mydatagridview.performlayout() after adding the arrows and now it renders ok
    • Marked as answer by VooDoo Chicken Tuesday, February 24, 2009 1:09 AM
    Tuesday, February 24, 2009 1:09 AM

All replies

  • forget it, now i am doing mydatagridview.performlayout() after adding the arrows and now it renders ok
    • Marked as answer by VooDoo Chicken Tuesday, February 24, 2009 1:09 AM
    Tuesday, February 24, 2009 1:09 AM
  • I have exactly the same phenomenon. Does anyone have an explanation for this. Do we really have to call Performlayout manually after adding rows?
    Monday, May 04, 2009 10:22 AM