To Call Cell Text Changed Event in DataGridView using C#

T.saravanan
Posted by T.saravanan under Windows Forms category on | Points: 40 | Views : 37791
Hi All,

Here i am given a code snippet for how to call (or) use text changed event in DataGridView Control.
In my form i am using DataGridView and TextBox Controls in a form.
This Code explain to set a Cell value into TextBox.

// Assign Control Object(declared as Global)
Control cntObject;

// Select DataGridView EditingControlShowing Event
Private void datagridview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.TextChanged +=new EventHandler(textBox_TextChanged);
cntObject=e.Control;
cntObject.TextChanged +=textBox_TextChanged;
}

// TextBox TextChanged Event
Private void textBox_TextChanged(object sender, EventArgs e)
{
if(cntObject.Text!=string.Empty)
{
textBox.Text=cntObject.Text;
}
}


I hope this Code snippet very useful to who need a textchanged event in DataGridView Control.

Cheers :)

Comments or Responses

Login to post response