have datagridview where are columns
lenght,width,qty, and readonly column M2 (where is calculated LxWxQ with CellEndEdit event )
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.
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. How can i fire the CellEndEdit event on each row??
I try already
dataGridView1.Upate();
dataGridView1.Refresh();
but without any change.
thank you
You can set the CurrentCell
and then to call 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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.