【问题标题】:Datagrid view show its values in GUI on header click?winformDatagridview 在标题单击时在 GUI 中显示其值?winform
【发布时间】:2016-11-03 12:31:52
【问题描述】:

当我在表单加载时将数据表分配为数据源时,我遇到了 GUI 问题,然后我使用 onlick 按钮填充数据表及其在网格视图中显示的行,但 GUI 问题是,只有当我更改位置时,图像行才以图形格式显示单击网格标题或移动行的形式,然后所有行都会出现,否则它们不会显示,请参见代码

加载表单

   private void WebScrapingApp_Load(object sender, EventArgs e)
    { datatable1.Columns.Add("catagory", typeof(System.String));
        datatable1.Columns.Add("PageNo", typeof(System.String));
        datatable1.Columns.Add("Name", typeof(System.String));
        datatable1.Columns.Add("price", typeof(System.String));
        datatable1.Columns.Add("Time", typeof(System.String));
        datatable1.Columns.Add("Location", typeof(System.String));
        dataGridView2.DataSource = datatable1;
        this.dataGridView2.Update();
    }

然后 onlclick 调用一个有循环添加行的函数

            for (int i = 3; i <= 41; i++)
                     {
                         try
                         {

   datatable1.Rows.Add(s, pageIndex.ToString(), tmpNames, tmpLocations, tmtimes, tmprices);
                             this.dataGridView2.Update();
                             datatable1.AcceptChanges();

                 }
       }

问题:如图所示,填充数据在单击标题行时变得可见,因为当您单击其标题时,第一个列在网格中仍然不可见

图形图片在链接下方

IMAGE OF PROBLEM SOME PART CLICK ME

【问题讨论】:

  • 你想说什么?按钮单击时标题行是否消失?
  • 没有点击它们出现
  • 好的,有什么问题?
  • 当我单击标题时,它们下面的数据变得可见,其他虎钳数据填充但没有出现这是我多次遇到的问题,只有在标题上单击下面的数据才可见,因为图像显示第一列仍然存在不可见,但是当我单击顶部标题时,它会出现
  • 由于网络安全隐私,我看不到图片。所以你想说你首先点击按钮然后什么都没有发生,然后你点击标题然后数据变得可见?是吗?

标签: c# winforms user-interface datagridview datagrid


【解决方案1】:

更新此按钮点击代码:

   for (int i = 3; i <= 41; i++)
      {
          try
            {

  datatable1.Rows.Add(s, pageIndex.ToString(), tmpNames, tmpLocations, tmtimes, tmprices);
  datatable1.AcceptChanges();   
  dataGridView2.DataSource = datatable1;               
  this.dataGridView2.Update();


          }
      }

或尝试以下方法:

创建一个绑定网格的方法:

 public void BindResultsTable()
    {
           datatable1=null;
            datatable1.Columns.Add("catagory", typeof(System.String));
            datatable1.Columns.Add("PageNo", typeof(System.String));
            datatable1.Columns.Add("Name", typeof(System.String));
            datatable1.Columns.Add("price", typeof(System.String));
            datatable1.Columns.Add("Time", typeof(System.String));
            datatable1.Columns.Add("Location", typeof(System.String));


          for (int i = 3; i <= 41; i++)
          {
              try
                {

      datatable1.Rows.Add(s, pageIndex.ToString(), tmpNames, tmpLocations, tmtimes, tmprices);
      datatable1.AcceptChanges();   


              }
          }
      dataGridView2.DataSource = null;
      dataGridView2.DataSource = datatable1;               
      this.dataGridView2.Update();
    }

在按钮点击事件上调用此函数:

        BindResultsTable();

也请访问:

How to add rows to datagridview winforms?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-04
    • 2012-02-16
    • 2013-12-24
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多