-
Feb 28th, 2013, 09:08 PM
#1
Thread Starter
Lively Member
Month Calender help
I have a button1 that when clicked, it opens a monthcalendar1 form. I would like to have the user select a date from the calendar and whatever date they selected shows up in the a textbox but in "yyMMdd" format. On some forums I've read, its states that if I want just the date and not the range I need to change the MaxSelectionCount=1 in the properties window and use the "monthcalendar.selectionend" in my code. Unfortunately no example of code was given. I'm not so worried about the date format right now but just getting it into the textbox. Any help greatly appreciated. Running visual studio 2010 in windows 7 if it helps.
-
Feb 28th, 2013, 09:30 PM
#2
Hyperactive Member
Re: Month Calender help
Just call
vbnet Code:
MonthCalendar1.SelectionRange.Start.ToString("yyMMdd")
also assign MaxSelectionCount = 1
-
Feb 28th, 2013, 11:59 PM
#3
Thread Starter
Lively Member
Re: Month Calender help
Thanks for the quick response. I'm sorry but I've should of started off by saying I'm new at programming with visual basic. How do link that to the textbox. All this is under the public class???? Where would this code be entered, the button1.click, monthCalendar1 or form1.load. Maxselection is already = 1.
Last edited by pooky; Mar 1st, 2013 at 12:03 AM.
-
Mar 1st, 2013, 04:10 PM
#4
Re: Month Calender help
TextBox1.Text = MonthCalendar1.SelectionRange.Start.ToString("yyMMdd")
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Mar 1st, 2013, 08:33 PM
#5
Hyperactive Member
Re: Month Calender help
Originally Posted by pooky
Where would this code be entered, the button1.click, monthCalendar1 or form1.load. Maxselection is already = 1.
You'll want to take what dunfiddlin suggested and place it in your method that handles the buttons click event.
vbnet Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Update the text every time the user clicks this button. TextBox1.Text = MonthCalendar1.SelectionRange.Start.ToString("yyMMdd") End Sub
-
Mar 1st, 2013, 09:21 PM
#6
Thread Starter
Lively Member
Re: Month Calender help
That worked. Thank you both very much for your help. Problem solved.
-
Mar 1st, 2013, 09:46 PM
#7
Thread Starter
Lively Member
Re: Month Calender help
Quick question. If I wanted to use this form to work with another form what would I need to add to this code? Would I have to embed it within a public class. For example:
Public Class txtDate.Text = MonthCalendar1.SelectionRange.Start.ToString("yyMMdd")
End Class
Would these two lines of code be entered in on the form with the calendar or on the form it'll be used in? Hope that made sense.
-
May 11th, 2013, 09:27 PM
#8
Thread Starter
Lively Member
Re: Month Calender help
It worked. Thank you so very much for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|