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?.
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
mahesh waghelaPosted Nov 6, 2011, 9:25 AM
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)
Sam HobbsPosted Nov 6, 2011, 2:40 AM
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 waghelaPosted Nov 6, 2011, 1:52 AM
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.
VulpesPosted Nov 5, 2011, 5:33 PM
Sam HobbsPosted Nov 5, 2011, 1:15 PM
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.