16,554
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication35
{
public partial class Form1 : Form
{
DataGridView DGV = new DataGridView();
TextBox TB = new TextBox();
public Form1()
{
InitializeComponent();
DGV.Columns.Add("c1", "c1");
DGV.Columns.Add("c2", "c2");
DGV.Rows.Add(new Object[] { 1, 2 });
DGV.Rows.Add(new Object[] { 3, 4 });
DGV.Parent = this;
DGV.SelectionChanged += new EventHandler(DGV_SelectionChanged);
TB.Location = new Point(0, 200);
TB.Parent = this;
}
void DGV_SelectionChanged(object sender, EventArgs e)
{
int Total = 0;
foreach (DataGridViewCell Cell in DGV.SelectedCells)
Total += (int)Cell.Value;
TB.Text = Total.ToString();
}
}
}