none
DataGridView text changed RRS feed

  • 问题

  • 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!
    2007年3月8日 15:47

答案

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

       }

    2007年3月12日 6:00

全部回复

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

    2007年3月9日 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");

       }

    2007年3月12日 6:00
  • Thank you. This is exactly what I wanted.
    2007年3月12日 12:53
  • Thank you. Really that i wanted...

    Partho 

    2010年6月12日 6:23
  • Hello

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

    Thanks

    2010年7月29日 10:32
  • Thanks a lot for giving this solution.
    2012年3月9日 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?
    2018年3月17日 16:40