0

i have a GUI problem when i assign datatable as datasource on formload, then onlick button i populate datatabel and its rows shown in grid view but GUI issue is that as shown in image row appear in graphical format only when i change the position of form of click on grid header or move row then all row appears other wise they are not shown see code

on load form

   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();
    }

then onlclick call a fucntion that have loop to ADD rows

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

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

                 }
       }

PROBLEM: as shown in image populated data become visible on click of header row, as first coloumn is still invisible in grid when you click its header it will appear

IMAGE FOR GRAPHICS IS BELOW LINK

IMAGE OF PROBLEM SOME PART CLICK ME

1 Answers1

0

Update this Button Click Code :

   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();


          }
      }

Or try the following approach :

Create a method to Bind the Grid :

 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();
    }

Call this function on button click event :

        BindResultsTable();

Visit this also :

How to add rows to datagridview winforms?

Community
  • 1
  • 1
Alina Anjum
  • 1,178
  • 6
  • 30
  • 53