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일 목요일 오후 3: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일 금요일 오후 2: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일 토요일 오후 4:40