I have Bound Datagridview and and trying to access of editing control as below:
private void newdgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (newdgv.CurrentCell.ColumnIndex ==0)
{
if (e.Control is TextBox)
{
TextBox tbox = e.Control as TextBox;
tbox.KeyDown += new KeyEventHandler(tbox_KeyDown);
tbox.TextChanged += new EventHandler(tbox_TextChanged);
}
}
}
private void tbox_TextChanged(object sender, EventArgs e)
{
TextBox tbox = (TextBox)sender;
if (tbox.Text.Length > 2)
{
listBox2.Visible = true;
button2.Visible = true;
int inddex = listBox2.FindString(tbox.Text);
if (inddex != -1)
{
listBox2.SetSelected(inddex, true);
listBox2.Focus();
}
}
tbox.TextChanged -= new EventHandler(tbox_TextChanged);
}Above at tbox_Texchanged EventHandller I am trying to Revoke the access of the same due to avoid of repeating same task on other columns's control. But it won't allow me above task. I can't see Listbox2 on passing the text limit of control.
Now look at the same example in other way:
private void newdgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (newdgv.CurrentCell.ColumnIndex ==0)
{
if (e.Control is TextBox)
{
TextBox tbox = e.Control as TextBox;
tbox.KeyDown += new KeyEventHandler(tbox_KeyDown);
tbox.TextChanged -= new EventHandler(tbox_TextChanged);
tbox.TextChanged += new EventHandler(tbox_TextChanged);
}
}
}
private void tbox_TextChanged(object sender, EventArgs e)
{
TextBox tbox = (TextBox)sender;
if (tbox.Text.Length > 2)
{
listBox2.Visible = true;
button2.Visible = true;
int inddex = listBox2.FindString(tbox.Text);
if (inddex != -1)
{
listBox2.SetSelected(inddex, true);
listBox2.Focus();
}
}
}Now see here it is allowed to see listbox2 on Column "0" and "1" Controls by passing of text limit. But I just want to fire the even on only column="0"'s Controls Not on Columns="1"'s Controls.
I Confused Bewteen Revoke the Access Of EventHandller.
How to Do?.

Sam HobbsRank #108 · 20.5K reputationPosted Nov 5, 2011, 9:15 AM EDT
I realize that it is unlikely that any of this applies, but if it does then it would explain what is happening and would be easy to overlook.
VulpesRank #55 · 29.2K reputationPosted Nov 5, 2011, 1:33 PM EDT
mahesh waghela88 reputationPosted Nov 5, 2011, 9:52 PM EDT
I have tried your two suggestion but it won't work I don't know why but I think I am agree with your point that it's create problem due to listbox2.focus();
hence I am try another similar example as below:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox tb = e.Control as TextBox;
if (dataGridView1.CurrentCell.ColumnIndex==0)
{
tb.TextChanged += new EventHandler(tb_TextChanged);
}
}
private void tb_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text.Length > 2)
{
listBox1.Visible = true;
listBox1.Focus();
}
tb.TextChanged -= new EventHandler(tb_TextChanged);
}
The above example I have debug and found that In tb_TextChanged EvenHandller the system Check Only TextBox tb = (TextBox)sender; and then after it jumped to direct tb.TextChanged -= new EventHandler(tb_TextChanged); That means it is not check the rest of code before Revocation of EventHandller with exceed of text limit of editing control and that's why The ListBox2 is not shown due to Revocation of EvenHandller before execution of rest of code.
Vulpes and Sam That's why I have found the solution with your both kind help and the solution I have Furnished as Below:
private void tb_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text.Length > 2)
{
listBox1.Visible = true;
listBox1.Focus();
tb.TextChanged -= new EventHandler(tb_TextChanged);
}
}
Now here above I just changed the revocation order of EventHandller. Now it is read with the text condition Limit. And working fine.
The above solution is found with both of your kind help. thanks lots. You both are genius. Thanks buddy.
Sam HobbsRank #108 · 20.5K reputationPosted Nov 5, 2011, 10:40 PM EDT
The bug is likely in your code, not the .Net code.
You have not told us the results of the diagnostics that I suggested doing in my first reply. Perhaps Vulpes distracted you by writing some code for you with the hope that it would solve the problem.
mahesh waghela88 reputationPosted Nov 6, 2011, 4:25 AM EST
Yes it is solved as I said in my previous reply. where I just debug similar example and solved it. And Here I also furnished the solution of original thread.
private void tbox_TextChanged(object sender, EventArgs e)
{ TextBox tbox = (TextBox)sender; if (tbox.Text.Length > 2) { listBox2.Visible = true; button2.Visible = true; int inddex = listBox2.FindString(tbox.Text); if (inddex != -1) { listBox2.SetSelected(inddex, true); listBox2.Focus(); tbox.TextChanged -= new EventHandler(tbox_TextChanged); } } Here above I have changed the orders of revocation EventHandller which will revoked the event after reading text limit of controls and rest of task of ListBox2. In my Original thread the revocation EventHandller is at main EventHandller Bracket and the same out of if condition of text limit of editing controls. Where the system reading it before text limit condition and hence it is revoked before reading text limit of editing control. But now it is reading after the text limit condition of editing control hence I think it is solved. The Solution is found with your both help. And once again I like to thanks buddy.