如何在编辑模式下设置datagridview的单元格值而不输入有效数据?

时间:2015-04-23 10:53:20

标签: c# windows datagridview cell editmode

看看这段代码 - 我完成了datagridview的CellEndEdit事件

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    try
    {
        if (e.ColumnIndex == 1)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[1].Value == null)
            {
                dataGridView1.Rows[e.RowIndex].Cells[4].Value = dataGridView1.Rows[0].Cells[6].Value;
            }

            else
            {
                con.Close();
                if (_chkval == 0)
                {
                    con.Open();
                    string query2 = "select [मालमत्ता क्रमांक] from नमुना८_मालमत्तेची_माहिती where [मालमत्ता क्रमांक] = '" + dataGridView1.CurrentRow.Cells[1].Value + "' ";
                    OleDbCommand adp2 = new OleDbCommand(query2, con);
                    OleDbDataReader dr = adp2.ExecuteReader();
                    if (dr.HasRows && dataGridView1.Rows[e.RowIndex].Cells[1].Value != null)
                    {
                        DialogResult result = MsgBox.Show("मालमत्ता क्रमांक अस्तित्वात आहे.", "सुचना", MsgBox.Buttons.OK, MsgBox.Icon.Warning, MsgBox.AnimateStyle.FadeIn);
                        dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[1];
                     this.dataGridView1.BeginEdit(false);
                    }
                    con.Close();
                }
            }

0 个答案:

没有答案