[英]c# after ds.readxml to datagridview how to fire CellEndEdit
have datagridview where are columns 有datagridview列在哪里
lenght,width,qty, and readonly column M2 (where is calculated LxWxQ with CellEndEdit event ) 长度,宽度,数量和只读列M2(其中使用CellEndEdit事件计算LxWxQ)
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int m2lenght = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
int m2width = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value);
int m2qty = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value);
float m2row = m2lenght * m2width * m2qty / 1000000F;
dataGridView1.CurrentRow.Cells[8].Value = m2row;
}
Can import xml file (with lenght, width, qty) throught dataset to datagridview. 可以通过数据集将xml文件(长度,宽度,数量)导入datagridview。
Import work fine. 导入工作正常。
private void XmlLoad(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml("D:\\test.xml");
foreach (DataRow item in ds.Tables["Data"].Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = item[0];
dataGridView1.Rows[n].Cells[1].Value = item[1];
dataGridView1.Rows[n].Cells[2].Value = item[2];
}
}
But after import the colummn M2 is without result. 但是导入后的M2列没有结果。 How can i fire the CellEndEdit event on each row?? 如何在每一行上触发CellEndEdit事件?
I try already 我已经尝试了
dataGridView1.Upate();
dataGridView1.Refresh();
but without any change. 但没有任何变化。
thank you 谢谢
You can set the CurrentCell
and then to call dataGridView1_CellEndEdit
: 您可以设置CurrentCell
,然后调用dataGridView1_CellEndEdit
:
private void XmlLoad(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml("D:\\test.xml");
foreach (DataRow item in ds.Tables["Data"].Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = item[0];
dataGridView1.Rows[n].Cells[1].Value = item[1];
dataGridView1.Rows[n].Cells[2].Value = item[2];
dateGridView1.CurrentCell = this.dateGridView1.Rows[n].Cells[0];
dataGridView1_CellEndEdit(this, null);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.