在窗体上定义了一个datagridview,datagridview的高度只够显示20行记录,初始时datagridview为空,程序动态地往datagridview中添加新行,当总函数未超过20行时没有异常,但是当超过21行时,滚动条无法显示,而且整个程序处于假死状态(通过查看日志文件,确定程序还在正常运行) 
而如果通过直接查询数据库,记录行数超过21行就可以显示滚动条,一切都正常,为什么动态添加新行时会出现这样的问题 
请高手路过解答一下。  

解决方案 »

  1.   

    看看是不是有什么paint事件?
      

  2.   

    datagridview的高度只够显示20行记录
    你设置datagridview限高了?看看这样:
     dataGridView1.ScrollBars = ScrollBars.Vertical;
      

  3.   

    DataGridView高度是固定的,当前页只可以显示20条记录,其他的就需要拖动滚动条了!往DataGridView中插入的数据是从其他地方读取过来的,每读取一条数据就插到DataGridView中,当数据太多时(大于20),滚动条不显示(有时显示但是拖不动),但是可以通过键盘的上下键来选择, 这个ScrollBars.Vertical不行!
      

  4.   

    你是直接操作datagridveiw添加一条数据,还是通过修改绑定的数据源增加一条数据呢?
      

  5.   

    你把DataGridView的设置代码贴出来看看,就是Form.Designer.cs中关于DataGridView的设置
      

  6.   

    DataGridView中的设置代码
    this.LV_SP.Activation = System.Windows.Forms.ItemActivation.OneClick;
                this.LV_SP.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                            | System.Windows.Forms.AnchorStyles.Right)));
                this.LV_SP.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                this.LV_SP.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                this.LV_SP.FullRowSelect = true;
                this.LV_SP.GridLines = true;
                this.LV_SP.Location = new System.Drawing.Point(2, 14);
                this.LV_SP.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
                this.LV_SP.Name = "LV_SP";
                this.LV_SP.Size = new System.Drawing.Size(313, 172);
                this.LV_SP.TabIndex = 4;
                this.LV_SP.UseCompatibleStateImageBehavior = false;
                this.LV_SP.MouseClick += new System.Windows.Forms.MouseEventHandler(this.LV_SP_MouseClick);
                this.LV_SP.DoubleClick += new System.EventHandler(this.LV_SP_DoubleClick);
      

  7.   

    这是datagridveiw的bug吗??楼主最终问题有没有解决阿??