如何在DataGridView中更改单元格值时运行CellEndEdit

时间:2017-07-27 10:00:02

标签: c# datagridview

当我编辑datagridview单元格时,CellEndEdit事件正在运行,但是当我将数据从数据库打印到DataGridView单元格时,CellEndEdit不起作用:

dataGridView1.Rows[0].Cells[0].Value = "test";

如何运行CellEndEdit

我的代码:

private void btnKaydet_Click(object sender, EventArgs e)
{
    try
    {
        int index = 2;
        int rc = gridView1.RowCount;
        for (int i = 0; i < rc; i++)
        {
            index++;
            string stk = gridView1.GetRowCellValue(i, "STOKKODU").ToString();
            string beden = gridView1.GetRowCellValue(i, "BEDEN").ToString();
            string mik = gridView1.GetRowCellValue(i, "MIKTARI_2").ToString();
            dataGridView1.Rows[index].Cells[0].Value = stk;
            dataGridView1.Rows[index].Cells[1].Value = beden;
            dataGridView1.Rows[index].Cells[2].Value = mik;
        }
        ExcelProje.Save();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    object hucre = ExcelSayfa.Cells[dataGridView1.CurrentCell.RowIndex + 2, dataGridView1.CurrentCell.ColumnIndex + 1];
    Excel.Range bolge = ExcelSayfa.get_Range(hucre, hucre);
    bolge.Value2 = dataGridView1.CurrentCell.Value;
}

0 个答案:

没有答案