none
DataGridView text changed

    Question

  • Hi. Is there a way to detect the text changed event in a DataGridViewCell in the same way as the TextChanged event in a regular TextBox? Thanks!
    Thursday, March 8, 2007 3:47 PM

Answers

  • yes I think you can use textchange event for a textboxcolumn like follow code, cast cell to textbox then add event

    hope it helps 

     

    private void Form1_Load(object sender, EventArgs e)

      {

          this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);

      }

    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 e)

       {

           MessageBox.Show("changed");

       }

    Monday, March 12, 2007 6:00 AM

All replies

  • It seems there is no event exacty gets fired during changing the text of cell(I'm not sure,albeit i've checked).There are events indicating the end of state change,value change,editing change.

    For the event of DGView ,see : http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview_events.aspx

     

    Thanx,

    Ch.T.Gopi Kumar.

    Friday, March 9, 2007 11:24 AM
  • yes I think you can use textchange event for a textboxcolumn like follow code, cast cell to textbox then add event

    hope it helps 

     

    private void Form1_Load(object sender, EventArgs e)

      {

          this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);

      }

    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 e)

       {

           MessageBox.Show("changed");

       }

    Monday, March 12, 2007 6:00 AM
  • Thank you. This is exactly what I wanted.
    Monday, March 12, 2007 12:53 PM
  • Thank you. Really that i wanted...

    Partho 

    Saturday, June 12, 2010 6:23 AM
  • Hello

    Changed works good. But i could not for KeyPress or Keydown. How can i do for them ?

    Thanks

    Thursday, July 29, 2010 10:32 AM
  • Thanks a lot for giving this solution.
    Friday, March 9, 2012 2:48 PM
  • This is not working if you have multiple columns of input in a same row. They all will share same textbox. Any solution?
    Saturday, March 17, 2018 4:40 PM