Vaish

Hi

I have a datetimepicker control in windows form (VB.net or VS 2005). and a textbox control.

My question:

When select the date from the datetimepicker the selected date should be display in the textbox.

Advance thanks




Re: Windows Forms Data Controls and Databinding How to get the date form the datetimepicker to textbox

oswaldorb

Suscribe to the ValueChanged event on the DateTimePicker:

DateTimePicker1.ValueChanged += new System.EventHandler(this.DateTimePicker1_ValueChanged);

And after that, you'll put this code on the delegate:

private void DateTimePicker1_ValueChanged(object sender, EventArgs e)

{

TextBox1.Text = DateTimePicker1.Value.ToShortDateString();

}

Or just go ToString("Format") and put the format you want to display the date.
Let me know how it goes.






Re: Windows Forms Data Controls and Databinding How to get the date form the datetimepicker to textbox

Vaish

Hi

I am using VB.net or VS 2005 and found the solution as follows

Datetimepicker1.Format = DateTimePickerFormat.Custom
Datetimepicker1.CustomFormat = "yyyy-MM-dd"
Textbox1.Text = Datetimepicker1.Value

The above works fine.
I have different question now. The format in the Datetimepicker is "yyyy-MM-dd"  BUT I am getting the dateformat in the textbox is "yyyy/MM/dd".

So how can I get the date format of  ("yyyy-MM-dd" ) in my textbox.   not yyyy/MM/dd






Re: Windows Forms Data Controls and Databinding How to get the date form the datetimepicker to textbox

Zhi-Xin Ye - MSFT

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)

{

DateTime date = this.dateTimePicker1.Value;

this.textBox1.Text = date.ToString("yyyy-mm-dd");

}