Cell Value Changing Event ,c#

前端 未结 3 1824
陌清茗
陌清茗 2021-01-21 22:48

I have a DataGridView in which there are 3 columns; Quantity, Rate and Amount.
The DataGridView is Editable. When I enter a value in the Rate Column then immediately the val

3条回答
  •  一个人的身影
    2021-01-21 23:01

    I have found no event that can handle the value of cell change properly.

    You must convert the editable cell into a Textbox, then provide the changed event on it.

    This is the code that i found while browsing one of the MSDN Forums:

    http://social.msdn.microsoft.com/Forums/windows/en-US/a56ac5c1-e71f-4a12-bbfa-ab8fc7b36f1c/datagridview-text-changed?forum=winformsdatacontrols

    I am also adding the code here:

    void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    
    {
    
       if (dataGridView1.CurrentCell.ColumnIndex == 0)
       {
    
          TextBox tb = (TextBox)e.Control;
          tb.TextChanged += new EventHandler(tb_TextChanged);
       }
    }
    
    void tb_TextChanged(object sender, EventArgs 
    {
       MessageBox.Show("changed");
    }
    

提交回复
热议问题