none
DataGridView Bug??? RRS feed

  • Question

  • 未处理System.ArgumentOutOfRangeException

      HResult=-2146233086

      Message=“24511”的值对于“Value”无效。“Value”应介于 'minimum' 和 'maximum' 之间。

    参数名: Value

      Source=System.Windows.Forms

      ParamName=Value

      StackTrace:

           在 System.Windows.Forms.ScrollBar.set_Value(Int32 value)

           在 System.Windows.Forms.ScrollBar.DoScroll(ScrollEventType type)

           在 System.Windows.Forms.ScrollBar.WmReflectScroll(Message& m)

           在 System.Windows.Forms.ScrollBar.WndProc(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           在 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)

           在 System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)

           在 System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)

           在 System.Windows.Forms.Control.WndProc(Message& m)

           在 System.Windows.Forms.DataGridView.WndProc(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)

           在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)

           在 System.Windows.Forms.Control.DefWndProc(Message& m)

           在 System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)

           在 System.Windows.Forms.Control.WndProc(Message& m)

           在 System.Windows.Forms.ScrollBar.WndProc(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

           在 System.Windows.Forms.Application.Run(Form mainForm)

           在 WindowsFormsApplication2.Program.Main() 位置 c:\Users\yansong1\Desktop\WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:行号 19

           在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           在 System.Threading.ThreadHelper.ThreadStart()

      InnerException:

     

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Diagnostics;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

     

    namespace WindowsFormsApplication2

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

     

            private void button1_Click(object sender, EventArgs e)

            {

                for (int i = 0; i < 5000; i++)

                {

                    DataGridViewRow row = ConverToRow();

                    dataGridView1.Rows.Add(row);

     

                }

                dataGridView1.PerformLayout();

            }

     

            private DataGridViewRow ConverToRow()

            {
                DataGridViewRow row = new DataGridViewRow();
                return row;
            }

     

            private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
            {
                try
                {
                    dataGridView1.SuspendLayout();

                    if (dataGridView1.Rows.Count > 200)

                    {

                        for (int i = 0; i < 200; i++)

                        {

                            DataGridViewRow row = dataGridView1.Rows[i];

     

                            dataGridView1.Rows.Remove(row);

                        }

                    }

                    else

                    {

                        //for (int i = 0; i < 200; i++)

                        //{

                        //    DataGridViewRow row = ConverToRow();

                        //    dataGridView1.Rows.Add(row);

                        //}

                    }

                    //ScrollBars temp = dataGridView1.ScrollBars;

                    //dataGridView1.ScrollBars = ScrollBars.None;

                    //dataGridView1.ScrollBars = temp;

                    //dataGridView1.FirstDisplayedScrollingRowIndex = e.NewValue;

                    dataGridView1.PerformLayout();

                }

                catch (Exception err)

                {

                    string aa = err.ToString();

                }
            }
        }
    }

     

    Wednesday, February 6, 2013 7:07 AM

Answers