472,952 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

dataGridView remove rows in Scroll event cause execption

I get "Value of '3720' is not valid for 'Value'. 'Value' should be
between 'minimum' and 'maximum' exception if I remove rows in a
dataGridView while scrolling from the top to the end of the grid in
one fell swoop. You can reproduce this using the code listed under
[1]. .NET 2.0 is used.

The only description of the exception found at Microsoft [2] was not
helpful.

As the exception occurs in
System.Windows.Forms.ScrollBar.set_Value(Int32 value) (see [3] for the
stack trace) I guess I have to reset a pointer or cancel the scrolling
event if it tries to scroll to rows which are not longer available.
But how to do that?

Note that the source code snippet below is not the actual program
code. But it perfectly illustrates the issue. Important is that you
scroll in one single move from the top to the end. Wondering if you
scroll row by row, the exception does not occur.

Thanks in advance.

Michael

[1] Program source code snippet
int testCount = 200;
public Form1()
{
InitializeComponent();
this.dataGridView1.Rows.Add(testCount);
}
private void dataGridView1_Scroll(object sender,
ScrollEventArgs e)
{
if (e.NewValue 150)
{
for (int i = testCount; i 150; i--)
{
this.dataGridView1.Rows.RemoveAt(i - 1);
}
e.NewValue = 100;
this.dataGridView1.FirstDisplayedScrollingRowIndex =
100;
}
}

[2] "System.ArgumentException: '0' is not a valid value for 'value'"
error message when you populate a DataGrid control in a Windows Forms
application
http://support.microsoft.com/kb/838087

[3] Exception and stack trace

Message = "Value of '3720' is not valid for 'Value'. 'Value' should be
between 'minimum' and 'maximum'.\r\nParameter name: Value"
Source "System.Windows.Forms" string
" at System.Windows.Forms.ScrollBar.set_Value(Int32 value)
at System.Windows.Forms.ScrollBar.DoScroll(ScrollEven tType type)
at System.Windows.Forms.ScrollBar.WmReflectScroll(Mes sage& m)
at System.Windows.Forms.ScrollBar.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessa ge(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.ReflectMessageInterna l(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.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& 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.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at tester.Program.Main() in ...\\tester\\Program.cs:line 19"

May 21 '07 #1
2 4158
I must admit that this seems a curious place to be deleting rows...
perhaps virtual mode would be a better solution?

http://msdn2.microsoft.com/en-us/library/2b177d6d.aspx

Marc
May 21 '07 #2
On May 21, 1:20 pm, "Marc Gravell" <marc.grav...@gmail.comwrote:
I must admit that this seems a curious place to be deleting rows...
perhaps virtual mode would be a better solution?

http://msdn2.microsoft.com/en-us/library/2b177d6d.aspx

Marc
Thanks for the hint Marc. "Virtual mode is designed for use with very
large stores of data" which is exactly what I have to handle. However,
I still getting the exception even deleting code was moved to

private void dataGridView_CellValueNeeded(object sender,
DataGridViewCellValueEventArgs e)

The issue I think is that I have a total account of rows which is
changing during runtime and which I have to handle. Adding rows is no
problem. But deleting if you scroll as described resulting in an
exception.

Does anyone could tell me the best practices to handle changing amount
of total rows in a dataGridView? The gird is not bound to an object.
Adding/deleting rows have to be coded.

Michael

May 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Arvind | last post by:
Hi I edit a cell in a DataGridView, and then would move to another cell in the DataGridView using mouse. Then the DataGridView as of now does scroll down to the last visited cell. But when I try...
0
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {...
2
by: Rich | last post by:
Hello, Some database applicatins have a tooltip feature where when you are dragging the scrollbar of the table view a tooltip appears next to the mouse cursor displaying the approximate record...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
2
by: lord.zoltar | last post by:
I have a DataGridView that has potentially several hundred rows (possibly a thousand or two). I'd like for each row to have the proper height to accomadate the text in the row. I tried setting the...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
0
by: =?Utf-8?B?aW1yYW4uYQ==?= | last post by:
Hi all, I am having a problem with inserting rows in to my datagridview control. The datagridview is bound to a bindingsource with a filter set. If i try and add a row to the datagridview while...
0
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
I edit a cell in a DataGridView, and then would move to another cell in the DataGridView using mouse. Then the DataGridView as of now does scroll down to the last visited cell. But when I try to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.