c# 用c1 datagrid添加合计行 中最后合计行列数与明细不一样

豆丁微信公众号
君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
C#中DataGrid使用技巧
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='http://www.docin.com/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口C#DataGridView 行记录上下移动
我的图书馆
C#DataGridView 行记录上下移动
&467人阅读&&&&经过自己一番简单的研究,发现在C#中实现很容易。自己临时写的,可能方法不是很好,但基本实现了预期的效果。[csharp]&[csharp]&
[转]&[转]&[转]&[转]&[转]&[转]&
喜欢该文的人也喜欢c# listview添加合计行
[问题点数:40分,结帖人wg5083]
本版专家分:0
结帖率 66.67%
CSDN今日推荐
本版专家分:314
本版专家分:1696
本版专家分:1713
本版专家分:314
本版专家分:0
结帖率 66.67%
本版专家分:3541
匿名用户不能发表回复!|
CSDN今日推荐/*************************************************
&*&作者:许清明
&*&Cnblogs:http://www.cnblogs.com/xvqm00
**************************************************/
using&System.Collections.G
using&System.C
using&System.T
using&System.Windows.F
namespace&WindowsApplication6
&&&&public&class&FormHelper
&&&&&&&&#region&添加一行
&&&&&&&&public&void&AddRow(DataGridView&dg,&string&value)
&&&&&&&&&&&&if&(dg.Rows.Count&&&<span style="color: #)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&DelRow(dg,&dg.Rows.Count&-&<span style="color: #);
&&&&&&&&&&&&}
&&&&&&&&&&&&dg.Rows.Add();
&&&&&&&&&&&&for&(int&i&=&<span style="color: #;&i&&&dg.Columns.C&i++)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&dg.Rows[dg.Rows.Count&-&<span style="color: #].Cells[i].Value&=&
&&&&&&&&&&&&}
&&&&&&&&&&&&dg.CurrentCell&=&dg.Rows[dg.Rows.Count&-&<span style="color: #].Cells[<span style="color: #];
&&&&&&&&&&&&TotalRow(dg);
&&&&&&&&#endregion
&&&&&&&&#region&编辑一行
&&&&&&&&public&void&EditRow(DataGridView&dg)
&&&&&&&&&&&&DelRow(dg,&dg.Rows.Count&-&<span style="color: #);
&&&&&&&&&&&&TotalRow(dg);&&
&&&&&&&&#endregion
&&&&&&&&#region&删除一行
&&&&&&&&public&void&DelRow(DataGridView&dg,int&index)
&&&&&&&&&&&&dg.Rows.Remove(dg.Rows[index]);
&&&&&&&&#endregion
&&&&&&&&#region&合计行
&&&&&&&&public&void&TotalRow(DataGridView&dg)
&&&&&&&&&&&&dg.Rows.Add();
&&&&&&&&&&&&DataGridViewRow&dgr&=&dg.Rows[dg.Rows.Count&-&<span style="color: #];
&&&&&&&&&&&&dgr.ReadOnly&=&true;
&&&&&&&&&&&&dgr.DefaultCellStyle.BackColor&=&System.Drawing.Color.K
&&&&&&&&&&&&dgr.Cells[<span style="color: #].Value&=&"合计";
&&&&&&&&&&&&for&(int&i&=&<span style="color: #;&i&&&dg.Rows.Count&-&<span style="color: #;&i++)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&dgr.Cells[<span style="color: #].Value&=&Convert.ToSingle(dgr.Cells[<span style="color: #].Value)&+&Convert.ToSingle(dg.Rows[i].Cells[<span style="color: #].Value);
&&&&&&&&&&&&}
&&&&&&&&#endregion
程序包下载:技术天地,我满心欢喜!
C# DataGridView添加合计行
不废话,代码示例如下
string strcon = "Integrated Security=SSPI;Persist Security Info=FInitial Catalog=Data Source=(local)";
string strsql="select * from class";
private DataTable dtshowdata()
SqlConnection con = new SqlConnection(strcon );
SqlCommand cmd = new SqlCommand(strsql ,con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GC.Collect();
con.Close();
private DataTable dtstaticdata()
DataTable dt = dtshowdata();
DataRow dr = dt.NewRow();
dr[0] = "统计";
dr[1] = dt.Compute("Sum(语文)", null);//无效的聚合函数 Sum()和类型 String 的用法 数据库中的数据类型必须是数字
dr[2] = dt.Compute("Sum(数学)",null);//求平均数avg;
dt.Rows.Add(dr);
private void Smot() //锁定统计行 不让排序
for (int i = 0; i &=dataGridView2.Columns.Count - 1; i++)//如果想让统计置顶 可以去掉=号;就可以选择置顶
dataGridView2.Columns[i].SortMode = DataGridViewColumnSortMode.NotS
private void button2_Click(object sender, EventArgs e)
this.dataGridView2.DataSource = dtshowdata();
private void button3_Click(object sender, EventArgs e)
this.dataGridView2.DataSource = dtstaticdata();
dataGridView2.Rows[dataGridView2.Rows.Count - 1].DefaultCellStyle.BackColor = Color.R
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 datagrid vb 行列 的文章

 

随机推荐