telerik winforms set date for datetimepicker from code

Ranorex Studio, Spy, Recorder, and Driver.
sarathijayapal
Posts: 3
Joined: Fri Jul 17, 2020 11:11 am

telerik winforms set date for datetimepicker from code

Post by sarathijayapal » Tue Aug 11, 2020 6:18 am

Hi,

I'm using ranorex studio to automate a winforms datetimepicker date selection dynamically. but its not working as expected. find the code snip i used to select date from code.

Code: Select all

	 Ranorex.DateTime startDatePicker = repo.StudyDates.StartDateSlicker;
         var startControl = new Ranorex.Control(startDatePicker);
	 startControl.SetPropertyValue("Value", System.DateTime.Parse(System.DateTime.Now.AddDays(-5).ToString()));
Please suggest any solution. Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: telerik winforms set date for datetimepicker from code

Post by odklizec » Tue Aug 11, 2020 7:35 am

Hi,

Have you tried the same with ranorex Recording module actions? My guess is, that the control requires mouse/keyboard action to trigger an event inside the control? So I would suggest to replicate the problem with recording module action. First, store the date in variable (using user code) and then use key sequence to fill the control.

Btw, you forgot to mention Ranorex version and attach Ranorex snapshot (NOT screenshot) of the control in question.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

sarathijayapal
Posts: 3
Joined: Fri Jul 17, 2020 11:11 am

Re: telerik winforms set date for datetimepicker from code

Post by sarathijayapal » Tue Aug 11, 2020 8:42 am

Hi odklizec,
Thanks for the suggestion below. but the repository updated after the recording have some lists and datetimepicker. i assume , i may need to set value to the list to update the date time picker but not sure. i did try with key sequence from variable, but key sequence not affecting the control.

i have attached the snapshot and ranorex version info. thanks in advance.

Ranorex version 9.3.1
.Net runtime version 4.00.30319.4200
You do not have the required permissions to view the files attached to this post.

sarathijayapal
Posts: 3
Joined: Fri Jul 17, 2020 11:11 am

Re: telerik winforms set date for datetimepicker from code

Post by sarathijayapal » Tue Aug 11, 2020 5:42 pm

I found the solution with the help of an existing thread in which you have already addressed. i have added some delays so that the control wont urge to select different dates instead given variable date. and the self click event required to close the expanded list. here is the code,

base thread which i didnt notice before raising this.
how-to-insert-a-date-in-a-datetimepicke ... t7837.html

Code: Select all

 private void SetStartDateTime()
        {
        	//To Set Start Date
         	Ranorex.DateTime startDatePicker = repo.StudyDates.StartDateSlicker.Self;
         	var startControl = new Ranorex.Control(startDatePicker);
         	startControl.SetPropertyValue("Text", startdate);
         	startDatePicker.Click();
         	Delay.Seconds(1); 
         	
         	// To Set Start Time
         	Ranorex.DateTime startTimePicker = repo.StudyDates.ContentPanel.StartTimePicker;
         	var startTimeControl = new Ranorex.Control(startTimePicker);
         	startTimeControl.SetPropertyValue("Text", startdate); 
         	Delay.Seconds(1);  	
         	
         	//here startdate is the variable with datetime format - 08-11-2020 12:18 PM
        }


Thank you.