3

I have a form and one data grid view ....

I am filling the datagrid view by uisng the below method

 private void EquipmentFinder_Load(object sender, EventArgs e)
 {

        productgridview.RowTemplate.Height = 130;

        var productsbycount = dbentity.products.GroupBy(x => x.product_Id)
                              .Select(a => new
                               {
                                     productid = a.Key,
                                     productnam = a.FirstOrDefault().product_Name,
                                     productimage = a.FirstOrDefault().product_Image,
                                     productdescr = a.FirstOrDefault().product_Description,
                                     stockavailable = a.Select(x=>x.product_Id).Distinct().Count()
                                      productprice = a.FirstOrDefault().product_Price
                               });

        productbindingsource.DataSource = productsbycount;
        productgridview.DataSource = productbindingsource; 
 }

that was fine ....

now I want to find the total number of rows in the datagrid view(Row Count) and i want to represent this in label......

would any one pls help on this by giving any solution.....

Many Thanks ......

Glory Raj
  • 17,397
  • 27
  • 100
  • 203

2 Answers2

3

just do

labelCount.Text = productgridview.Rows.Count.ToString("n0");

what is the problem with this?

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • thanks a lot for `"n0"` format I really like this small finishing touch +1 I wish you update your answer with more formats details – sam Feb 09 '18 at 12:46
2
productgridview.Rows.Count;

should give you the number of rows in the DataGridView. If you then want to set a label to have that text,

label.Text = productgridview.Rows.Count.ToString();

will set the label to display with the number of rows.

Ben
  • 111
  • 4