Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a combo box (cmbBatchNo) in which I can load the list of items. When we select one item in list of items then Selectedindexchanged event is fired and if I enter new number in the combo box then the text changed event is fired and disables the expdate, MRP textboxes but here its not fire.

Please help me.
C#
public void cmbBatchno_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ViewState["BatchNo"] != null)
        {
            DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
            for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
            {
                if (dtBatchNoDtls.Rows[i]["BatchNo"].ToString() == cmbBatchno.Text)
                {
                    txtExpdate.Text = dtBatchNoDtls.Rows[i]["ExpDate"].ToString();
                    txtMRP.Text = dtBatchNoDtls.Rows[i]["MRP"].ToString();
                    txtRate.Text = dtBatchNoDtls.Rows[i]["Rate"].ToString();
                    if (txtExpdate.Text != "")
                        txtPacks.Focus();
                    else
                        txtExpdate.Focus();
                    break;
                }
                else
                {
                    txtExpdate.Text = string.Empty;
                    txtMRP.Text = "";
                    txtRate.Text = "";
                }
            }
        }
    }

    public void cmbBatchno_TextChanged(object sender, EventArgs e)
    {
        if (ViewState["BatchNo"] != null)
        {
            DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
            for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
            {
                if (cmbBatchno.Text == dtBatchNoDtls.Rows[i]["BatchNo"].ToString())
                {
                    txtExpdate.Enabled = false;
                    txtMRP.Enabled = false;
                    break;
                }
                else
                {
                    txtExpdate.Enabled = true;
                    txtMRP.Enabled = true;
                }
            }
               
        }
    

    }
Posted
Updated 18-Oct-13 23:46pm
v3

1 solution

The code you have written in cmbBatchno_TextChanged event is that if the value selected in cmbBatchno(combobox) matches with the number from retrieved data, then it will disable the textbox.
see your code
C#
if (cmbBatchno.Text == dtBatchNoDtls.Rows[i]["BatchNo"].ToString())
{
    txtExpdate.Enabled = false;
    txtMRP.Enabled = false;
    break;
}                
you have written
C#
txtExpdate.Enabled = false;
which disables the textbox. if you want that the textbox should not be disabled then make it true instead of false in if condition. like this
txtExpdate.Enabled = true;


Any help needed plz reply.
 
Share this answer
 
Comments
MANI 14 21-Oct-13 2:23am    
k but cmbBatchno_TextChanged is not executed when changed the text in comboBox(cmbbatchno) is there any wrong.. pls help me
Ank_ush 21-Oct-13 12:43pm    
select thecmbBatchno(combobox) on form, go to properties and check the text_changed event, is it empty or filled, if it's empty then write the same code again for the Text_Changed event, even if it's not empty still delete the event and write the same code again
MANI 14 22-Oct-13 0:40am    
if u dnt mine show me one example pls

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900