C# .NET - binding of date time picker - Asked By Priyanka on 31-Aug-10 08:13 AM

i have one date time picker  and two text boxes ...i want whatever value i enter in textbox1 , it add it to the days of the date time picker and give result in textbox2....
 i am begineer in C# plz help...
Sagar P replied to Priyanka on 31-Aug-10 08:33 AM

You can try following code to get result;

 

DateTime dt = Convert.ToDateTime(dateTimePicker1.Value);

textBox2.Text = Convert.ToString(dt.AddDays(Convert.ToDouble(textBox1.Text)));

It will add days you entered in textbox1 to your picked date of datetimepicker and will display result in textbox2

Anand Malli replied to Priyanka on 31-Aug-10 08:39 AM
Hi Dvarkin,

I have created one desktop apps for you which has threee controls two textbox and one dt picker right,now what i have done is i have written Key Press event for first textbox in which you will be entering months in int data type,here i have not check if the value is int or not,because you can put that check at your end,and i have added that many days to dt picker and displayed it in textbox2 as you said,just see the code below which is written on first textbox's keypress event

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
  dateTimePicker1.Value = DateTime.Now;
  if (e.KeyChar == 13)
  {
   dateTimePicker1.Value =
Convert.ToDateTime(dateTimePicker1.Value).AddMonths(Convert.ToInt32(textBox1.Text));
        textBox2.Text = dateTimePicker1.Value.ToString();
   }
}

Here see the first line i have reset the value of dt picker everytime use presses enter because otherwise it will keep on adding the year to old values...see the over all effect after adding month



i think this is what you want right

let me know
thxs
Super Man replied to Priyanka on 31-Aug-10 10:10 AM

No need to write multiple post,

See this your previous post.

http://www.eggheadcafe.com/community/aspnet/2/10197145/binding-with-date-time-picker.aspx

 

Goniey N (Mr. G) replied to Priyanka on 31-Aug-10 11:26 AM
Why Are You Increasing The Forum Size by Asking Same Question twice?

If you Post Your Question Once Then No Need To Ask Again. Check your Post Because When you Post Your Code At That Time It's Not Possible that Everybody Will give You Answer Quickly. After Some time You Have To Check that Is there Any New Answer or Not.. If you Don't Want To Do It Then You Can Check Your Mails In That It Will Show You That Is There Any Post Or Not...


You Can Check The Answer Of My By Clicking The Below Link :



-- Hope You Understand....