how I can show the sum of in a datagridview column?

后端 未结 8 1433
日久生厌
日久生厌 2020-11-27 05:46

I need to show the sum of the count column from this datagridview, but I don\'t know how I can get to the data in the datagridview.

When I

相关标签:
8条回答
  • 2020-11-27 06:38

    you can do it better with two datagridview, you add the same datasource , hide the headers of the second, set the height of the second = to the height of the rows of the first, turn off all resizable atributes of the second, synchronize the scrollbars of both, only horizontal, put the second on the botton of the first etc.

    take a look:

       dgv3.ColumnHeadersVisible = false;
       dgv3.Height = dgv1.Rows[0].Height;
       dgv3.Location = new Point(Xdgvx, this.dgv1.Height - dgv3.Height - SystemInformation.HorizontalScrollBarHeight);
       dgv3.Width = dgv1.Width;
    
       private void dgv1_Scroll(object sender, ScrollEventArgs e)
            {
                if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
                {
                    dgv3.HorizontalScrollingOffset = e.NewValue;
                }
            }
    
    0 讨论(0)
  • 2020-11-27 06:38
    //declare the total variable
    int total = 0;
    //loop through the datagrid and sum the column 
    for(int i=0;i<datagridview1.Rows.Count;i++)
    {
        total +=int.Parse(datagridview1.Rows[i].Cells["CELL NAME OR INDEX"].Value.ToString());
    
    }
    string tota
    
    0 讨论(0)
提交回复
热议问题