Dev-GridView-对于gridview的列值的合计⽅法1:控件⾃带
进⼊Run Designer:
①设置属性:Views-Options-OptionsView-ShowFooter=true
②对于需要值操作的列进⾏操作:SummaryItem-SummaryType-Sum(可以设置sum,max,min,等)
⽅法2:重写⽅法
//要操作的表
dt;
//添加显⽰合计的⼀⾏
if (dt.Rows.Count > 0)
{
DataRow dr = dt.NewRow();
dr[m_PrimarColumNm] = "合计";
SetSum(ref dr, dt, “需要合计的列名”);
dt.Rows.Add(dr);
}
/// <summary>
/
// 统计表格列的总和(对于求和的列必须为数字类型)
/// </summary>
/// <param name="dr">显⽰合计的⼀⾏</param>
/// <param name="dt">要操作的表格</param>
gridview不显示/// <param name="colunNm">要求和的列</param>
private void SetSum(ref DataRow dr, DataTable dt, string colunNm)
{
try
{
dr[colunNm] = "0";
foreach (DataRow item in dt.Rows)
{
dr[colunNm] = (Convert.ToInt32(dr[colunNm].ToString()) + Convert.ToInt32(item[colunNm].ToString())).ToString();
}
}
catch (Exception ex)
{
throw ex;
}
}
⽅法3:没实现的⽅法
//gridView1.OptionsView.ShowFooter = true;
//gridView1.GroupSummary.Clear();
///⽅法1
//gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "列名", 表格列, "组计:{0}");
///⽅法2
//GridGroupSummaryItem item1 = new GridGroupSummaryItem();
//item1.FieldName = "s1";
//item1.SummaryType = DevExpress.Data.SummaryItemType.Sum;
//item1.DisplayFormat = "";//格式
//item1.ShowInGroupColumnFooter = s1;
//item1.ShowInGroupColumnFooterName = "s1";
//这句就是给groupcolumnfooter加上
//gridView1.GroupSummary.Add(item1);
///⽅法3(设计器⽅法)
this.s1.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum)});
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论