繁体   English   中英

ds.readxml之后的c#到datagridview后如何触发CellEndEdit

[英]c# after ds.readxml to datagridview how to fire CellEndEdit


有datagridview列在哪里
长度,宽度,数量和只读列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;
        }


可以通过数据集将xml文件(长度,宽度,数量)导入datagridview。
导入工作正常。

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];
            }
         }

但是导入后的M2列没有结果。 如何在每一行上触发CellEndEdit事件?

我已经尝试了

dataGridView1.Upate();
dataGridView1.Refresh();

但没有任何变化。

谢谢

您可以设置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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM