none
DataGridView text changed RRS feed

  • Pergunta

  • 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!
    quinta-feira, 8 de março de 2007 15:47

Respostas

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

       }

    segunda-feira, 12 de março de 2007 06:00

Todas as Respostas

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

    sexta-feira, 9 de março de 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");

       }

    segunda-feira, 12 de março de 2007 06:00
  • Thank you. This is exactly what I wanted.
    segunda-feira, 12 de março de 2007 12:53
  • Thank you. Really that i wanted...

    Partho 

    sábado, 12 de junho de 2010 06:23
  • Hello

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

    Thanks

    quinta-feira, 29 de julho de 2010 10:32
  • Thanks a lot for giving this solution.
    sexta-feira, 9 de março de 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?
    sábado, 17 de março de 2018 16:40