i'm working in c# winforms where i have put some code in textchange event of two textboxes
now i want when i select one textbox say textboxA its event of textchanged invoked and some result comes in textboxB at this point of time textboxB , its textxhanged event should not work.
is it possible ?
Loading

Sivaraman DhamodaranPosted Jul 11, 2014, 5:18 AM
private void comboProname_SelectedIndexChanged(object sender, EventArgs e)
{
// this is not working no error no exception
this.comboBthNo.SelectedIndexChanged -= new System.EventHandler(this.comboBthNo_SelectedIndexChanged);
cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + comboProname.Text + "'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection7 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection9 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection10 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection11 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection7.Add(reader["P_batchno"].ToString());
MyCollection9.Add(reader["P_max_stk"].ToString());
MyCollection10.Add(reader["P_min_stk"].ToString());
MyCollection11.Add(reader["P_vat"].ToString());
comboBthNo.Items.Add(reader["p_batchno"].ToString());
tbMaxStk.Text = (reader["P_max_stk"].ToString());
tbMinstk.Text = (reader["P_min_stk"].ToString());
tbVAT.Text = (reader["P_vat"].ToString());
}
comboBthNo.AutoCompleteCustomSource = MyCollection7;
tbMaxStk.AutoCompleteCustomSource = MyCollection9;
tbMinstk.AutoCompleteCustomSource = MyCollection10;
tbVAT.AutoCompleteCustomSource = MyCollection11;
conn.Close();
this.comboBthNo.SelectedIndexChanged += new System.EventHandler(this.comboBthNo_SelectedIndexChanged);
}
I hope the code marked in red indicates that change in the Index for the currently selected item of comboBthNo
varsha dodiyaPosted Jul 11, 2014, 2:59 AM
i have two combo boxes now 1 is for product name,2nd is for BatchNo. which are set auto filled from DB . now i want when i put product name in combo box1 the related values in combobox n other textbox should be fetched. i am doing it by comboProname_SelectedIndexChanged(object sender, EventArgs e) but its not working but when i put same code in textbox_e_TextChanged event it is working fine.but i want to do it with combo box only and with that i want same working (when i select or write text in combobox2 values should b fetched in other combo box and textbox) for another combo box too i.e. combobox for batchno.
My code is here...
/* private void tbProNAme_TextChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + tbProNAme.Text + "'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection7 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection9 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection10 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection11 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection7.Add(reader["P_batchno"].ToString());
MyCollection9.Add(reader["P_max_stk"].ToString());
MyCollection10.Add(reader["P_min_stk"].ToString());
MyCollection11.Add(reader["P_vat"].ToString());
comboBthNo.Items.Add(reader["p_batchno"].ToString());
tbMaxStk.Text = (reader["P_max_stk"].ToString());
tbMinstk.Text = (reader["P_min_stk"].ToString());
tbVAT.Text = (reader["P_vat"].ToString());
}
comboBthNo.AutoCompleteCustomSource = MyCollection7;
tbMaxStk.AutoCompleteCustomSource = MyCollection9;
tbMinstk.AutoCompleteCustomSource = MyCollection10;
tbVAT.AutoCompleteCustomSource = MyCollection11;
conn.Close();
} */ // this is code i tried for textbox and it is working
private void comboBthNo_SelectedIndexChanged(object sender, EventArgs e)
{ //i want dis to be disable when comboProname_selectedIndexchanged is enabled .
cmd = new SqlCommand("SELECT P_name from PRO where P_batchno='"+comboBthNo.Text+"'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection5 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection9 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection10 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection11 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection5.Add(reader["P_name"].ToString());
MyCollection9.Add(reader["P_max_stk"].ToString());
MyCollection10.Add(reader["P_min_stk"].ToString());
MyCollection11.Add(reader["P_vat"].ToString());
comboBthNo.Items.Add(reader["p_batchno"].ToString());
tbProNAme.Text = reader["P_name"].ToString();
tbMaxStk.Text = (reader["P_max_stk"].ToString());
tbMinstk.Text = (reader["P_min_stk"].ToString());
tbVAT.Text = (reader["P_vat"].ToString());
}
tbProNAme.AutoCompleteCustomSource = MyCollection5;
tbMaxStk.AutoCompleteCustomSource = MyCollection9;
tbMinstk.AutoCompleteCustomSource = MyCollection10;
tbVAT.AutoCompleteCustomSource = MyCollection11;
conn.Close();
}
private void comboProname_SelectedIndexChanged(object sender, EventArgs e)
{
// this is not working no error no exception
cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + comboProname.Text + "'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection7 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection9 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection10 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection11 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection7.Add(reader["P_batchno"].ToString());
MyCollection9.Add(reader["P_max_stk"].ToString());
MyCollection10.Add(reader["P_min_stk"].ToString());
MyCollection11.Add(reader["P_vat"].ToString());
comboBthNo.Items.Add(reader["p_batchno"].ToString());
tbMaxStk.Text = (reader["P_max_stk"].ToString());
tbMinstk.Text = (reader["P_min_stk"].ToString());
tbVAT.Text = (reader["P_vat"].ToString());
}
comboBthNo.AutoCompleteCustomSource = MyCollection7;
tbMaxStk.AutoCompleteCustomSource = MyCollection9;
tbMinstk.AutoCompleteCustomSource = MyCollection10;
tbVAT.AutoCompleteCustomSource = MyCollection11;
conn.Close();
}
Plz help me out .. thanks
Ranjit PowarPosted Jul 11, 2014, 2:36 AM
this.button1.Click -= new System.EventHandler(this.button1_Click);
varsha dodiyaPosted Jul 11, 2014, 2:24 AM
do i need to subscribe enter event ?
Sivaraman DhamodaranPosted Jul 11, 2014, 2:06 AM
The textbox is provided by Dotnet framework and when you change something the event will get fired. You can't stop firing an event as it is done by the dot.net framework.
OK. But the handler code can be controlled. That is you can subscribe for the text change event or un-subscribe.
For Example (The Click event handler for button):
Let us say you placed a button in the form and double clicked the button to have event handler function. Now searching the code find something like the below code
this.button1.Click += new System.EventHandler(this.button1_Click);
Now to Unsubscribe the event click with the handler function private void button1_Click(object sender, EventArgs e), you should call:
this.button1.Click -= new System.EventHandler(this.button1_Click);
Hope this helps.