Question

I have windows form containing tab control, having two tab pages

enter image description here

on form load event i passed value to datetimpicker1 exists on tab page 2

private void Form1_Load(object sender, EventArgs e)
    {
      dateTimePicker1.Text = "2014-05-14 00:00:00.000";    
    }

and on check button click event i have following code

 private void button2_Click(object sender, EventArgs e)
    { 
        MessageBox.Show(dateTimePicker1.Value.ToString());
        MessageBox.Show(dateTimePicker1.Text.ToString());
    }

output:

enter image description here

2)on navigating to tabpage2 & then click on check button

enter image description here

output:

enter image description here

& then after come back to tabpage1 & click on check it shows correct output

enter image description here

why it not showing at first time as we open form & clcik on check button without going to tab page 2

Your suggestions will be appreciated.

Was it helpful?

Solution

Check out MSDN Reference:

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown.

In form load you can select your tab as well.

private void Form1_Load(object sender, EventArgs e)
    {
        tabControl1.SelectedTab = tabPage2;
        dateTimePicker1.Text = "2014-05-14 00:00:00.000";            
    }

OTHER TIPS

This is the quote from MSDN

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown.

You can, for example, programmatically switch to tabPage2 and back to the first tab.

Try this one

   private void button2_Click(object sender, EventArgs e)
    { 
        MessageBox.Show(dateTimePicker1.Value.ToString());
        MessageBox.Show(dateTimePicker2.Value.ToString());
     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top