110,536
社区成员
发帖
与我相关
我的任务
分享
private void DGV_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
//有数据时取消默认选中第一行
if (this.DGV.Rows.Count > 0)
{
this.DGV.Rows[0].Selected = false;
}
//在首列自动排序号
for (int i = 0; i < DGV.Rows.Count; i++)
{
int j = i + 1;
DGV.Rows[i].HeaderCell.Value = j.ToString();
DGV.Rows[this.DGV.Rows.Count - 1].HeaderCell.Value = j.ToString("合计");//最后一行显示合计
}
//底部合计
Double he1 = 0;//积分
Double he2 = 0;//余额
Double he3 = 0;//金额
for (Int32 ih = 0; ih < DGV.Rows.Count - 1; ih++)
{
he1 += Convert.ToDouble(this.DGV.Rows[ih].Cells["Score"].Value);//积分
he2 += Convert.ToDouble(this.DGV.Rows[ih].Cells["Yue"].Value);//余额
he3 += Convert.ToDouble(this.DGV.Rows[ih].Cells["Mem_fst_amt"].Value);//金额
}
DataGridViewRow dgr = DGV.Rows[DGV.Rows.Count - 1];
dgr.Cells["Score"].Value = he1;////积分
dgr.Cells["Yue"].Value = he2;//余额
dgr.Cells["Mem_fst_amt"].Value = he3;//金额
}
private void DGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//设置最后一行,合计行的参数
DataGridViewRow dgr = DGV.Rows[DGV.Rows.Count - 1];
dgr.DefaultCellStyle.BackColor = Color.FromArgb(227, 244, 255);//背景颜色
dgr.DefaultCellStyle.Font = new Font("宋体", 9, FontStyle.Bold);//字体大小
dgr.DefaultCellStyle.ForeColor = Color.DodgerBlue;//字体颜色
}
private void DGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//设定DGV,值符合的行,字体颜色,最后一行除外
for (int i = 0; i < DGV.Rows.Count - 1; i++)
{
//亏本销售
if ((int)DGV.Rows[i].Cells["Addssl"].Value != 0 && (decimal)DGV.Rows[i].Cells["Addyl"].Value < 0)
{
DGV.Rows[i].DefaultCellStyle.ForeColor = Color.Red;//红色
}
}
}
private void DGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
//单击取消选中最后一行.必须取消,否则全选时,双击就出错
DGV.Rows[this.DGV.Rows.Count - 1].Selected = false;
}