111,129
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public Form1() {
InitializeComponent();
dataGridView1.DataSource = new BindingList<Model>();
}
private class Model : INotifyPropertyChanged
{
private int a = 0;
private int b = 0;
public int A { get { return a; } set { a = value; NotifyProerptyChanged("A"); NotifyProerptyChanged("C"); } }
public int B { get { return b; } set { b = value; NotifyProerptyChanged("B"); NotifyProerptyChanged("C"); } }
public int Result { get { return a * b; } }
private void NotifyProerptyChanged(string strPropName) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(strPropName));
}
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
{
int x1 = 0, x2 = 0;
int.TryParse(this.dataGridView1[0, e.RowIndex].FormattedValue.ToString(), out x1);
int.TryParse(this.dataGridView1[1, e.RowIndex].FormattedValue.ToString(), out x2);
int result = x1 * x2;
this.dataGridView1[2, e.RowIndex].Value = result;
}
}