I am dealing with a problem in which i got struck , which I asked at Events calling twice error on DataGridView . Now a respected member suggest me to remove the eventhandlers of the textbox inside of the datagridview before I add them again . But I cannot get the concept as i am just a beginner . Can someone please suggest me how to do it . The actual problem was that the OnEnter event of the customdatagridview was firing twice .The code was
public partial class CustomControl1 : DataGridView
{
public CustomControl1()
{
this.KeyDown += new
KeyEventHandler(CustomDataGridView_KeyDown);
InitializeComponent();
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
this.CurrentCell = this.Rows[0].Cells[0];
this.BeginEdit(true);
}
now the form where I am using.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
customControl11.Focus();
}
private void customControl11_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (customControl11.CurrentCell.ColumnIndex == 0)
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
textBox.TextChanged += TextBox_TextChanged;
textBox.KeyDown += TextBox_KeyDown;
textBox.Enter += TextBox_Enter;
}
}
}