none
DataGridView text changed RRS feed

  • Frage

  • 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!
    Donnerstag, 8. März 2007 15:47

Antworten

  • 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");

       }

    Montag, 12. März 2007 06:00

Alle Antworten

  • 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.

    Freitag, 9. März 2007 11:24
  • 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");

       }

    Montag, 12. März 2007 06:00
  • Thank you. This is exactly what I wanted.
    Montag, 12. März 2007 12:53
  • Thank you. Really that i wanted...

    Partho 

    Samstag, 12. Juni 2010 06:23
  • Hello

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

    Thanks

    Donnerstag, 29. Juli 2010 10:32
  • Thanks a lot for giving this solution.
    Freitag, 9. März 2012 14:48
  • This is not working if you have multiple columns of input in a same row. They all will share same textbox. Any solution?
    Samstag, 17. März 2018 16:40