Unable to Fetch Textbox values before ShowDialog in winforms

الإجابة Unable to Fetch Textbox values before ShowDialog in winforms

  • 2012年5月1日 上午 10:45
     
      包含代碼
        //Form1 Code. That calls form2
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 objDlg = new Form2();
                SqlConnection con = new SqlConnection("connectionstring");
                SqlDataAdapter dap = new SqlDataAdapter("select * from employee where id =1", con);
                dap.Fill(objDlg.ds);
                objDlg.LoadData();
            }
        }


        //Form 2 Code
        public partial class Form2 : Form
        {
            public DataSet ds = new DataSet();
            public Form2()
            {
                InitializeComponent();
            }
            public void LoadData()
            {
                textBox1.DataBindings.Add("Text", ds.Tables[0], "FirstName");
                if (textBox1.Text != "")
                {
                    //I am not able to enter this block, even though i have value in my dataset. 
                    //But the text box is getting the value when it opens. i mean after showdialog box.
                    checkBox1.Checked = true;
                }
                this.ShowDialog();
            }
        }

    I have Form1 and Form2. I am calling Form2 from Form1. I am binding the controls in form2 using a datasource. I have two controls in form2, a text box and a check box. I want to enable the check box based on the content available in text box. But its not working. Look the code above to get more clarity.

    Thanks in advance,

    Ganesh

所有回覆