473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

DateTimePicker event in C#.net

92
Hi All,
Can anyone suggest me, to display error message as"Select Valid Date", wht event i cn use for DateTimePicker. If i use leave event, user can change the date by closeup event, It should not happen. If i use both leave and closeup it posting the error message twice. Suggest whtz the correct value to display tht Error at single time, itz should not happen, whn i click another control(like textbox,button).
Reply me fast.
Thanks in Advance.
Jul 3 '09 #1
7 10906
tlhintoq
3,525 Expert 2GB
Please take a look at this posting guidelines topic regarding the use of abbreviations and SMS style text.

http://bytes.com/faq.php?faq=posting...ask_a_question

I genuinely want to see people get answers to their questions/problems. But speaking for myself, when its as much work to decypher the question as it to come up with a solution I stop reading the question about half way through the first paragraph. My general though process is something like: "If its not important enough to the poster to use all the letters in the words, why should I consider it important enough to read?"

wht
cn
whtz
tht
whn
i (instead of capital 'I')

These did not come from an on-line translator or foreign language to English dictionary. This is just ebonics for the keyboard.
Jul 3 '09 #2
tlhintoq
3,525 Expert 2GB
Can anyone suggest me, to display error message as"Select Valid Date"
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show("Please select a valid date", "Invalid date");
wht event i cn use for DateTimePicker
With any control, a good place to start is the default event. This will be the event that most people, mostly commonly need from a control. In this case the "value changed" event is the default for a DateTimePicker. After dragging your DateTimePicker from the toolbox to the form designer, just double-click the DateTimePicker. Visual Studio will add an empty method for you for the "value changed" event.
Expand|Select|Wrap|Line Numbers
  1.         private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.         }
Suggest whtz the correct value to display tht Error at single time, itz should not happen, whn i click another control(like textbox,button).
I have no idea what this is asking.
Jul 3 '09 #3
cloud255
427 Expert 256MB
@Limno
I think the OP doesn't want validation to occur for all controls on the page, only one control validated at a time before it loses focus. Then again I might be totally wrong (guessing here).

But if my guess is correct, the method suggested by tlhintoq will work perfectly i.e. code validation into the control's default behavior.
Jul 3 '09 #4
Limno
92
yes Cloud255, you are right, my code is just like this

if (dtpdate.text==convert.tostring(datetime.now()))
{
textbox1.text=0;
dtpdate.text="";
return;
}

I am writing this code in valuechange event, everytime dtpdate getting clear, so value is changing, it repeating its event. If i use closeup event, user changing value using keyboard, to avoid this i m using LEAVE event too, but everytime that message gets displaying. Suggest me good code.
Jul 3 '09 #5
cloud255
427 Expert 256MB
Hi,

I'm sorry, but I cannot seem to understand what you are trying to say, I understand that English is probably not your first language, but I really cannot figure out what the problem is.

Perhaps you know someone more apt in English who could help you describe your situation to us?
Jul 6 '09 #6
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. if (dtpdate.text==convert.tostring(datetime.now()))
  2. {
  3. textbox1.text=0;
  4. dtpdate.text="";
  5. return;
  6. }
Based on the notation... dtpdate is the DateTimePicker control. And you're clearing that by just changing the text. I don't think you can really change the *value* of a DTP by setting the text to null.
everytime dtpdate getting clear, so value is changing, it repeating its event.
Of course you are getting an infinite loop...
You are setting the text of the textbox to null
You are setting the text of the DTP to null
Then you do a comparrison to see if they are the same, which they are.
Then do it all over again. and again. and again.
Null == Null
Jul 6 '09 #7
Fr33dan
57
If I understand the problem correctly that infinite loop is the problem. I think the poster wants to check validity as the user enters each value but is encountering that loop. The Leave won't work because the user can close the form before it is run.

You could use a boolean flag to determine if you actually wanted to validate your data and then set it false when your changing the value. See this code:

Expand|Select|Wrap|Line Numbers
  1.         bool validate = true;
  2.  
  3.         private void dtpdate_ValueChanged(object sender, EventArgs e)
  4.         {
  5.             if (validate)
  6.             {
  7.                 validate = false;
  8.  
  9.                 if (dtpdate.text==Convert.ToString(DateTime.Now()))
  10.                 {
  11.                     textbox1.Text=0;
  12.                     dtpdate.Text="";
  13.                 }
  14.  
  15.                 validate = true;
  16.             }
  17.         }
  18.     }
There is probably a better way but this will work. (If I understand the problem correctly)
Jul 6 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Angelina | last post by:
Hi, I have got two DateTimePicker's on my form to accept a guest arrival date and departure date.what i want to acheieve is ensure that the DateTimePicker2 (departure) is always greater than...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
5
by: Alpha | last post by:
I have a DateTimePicker control that originally displays "1/1/1900" on screen. I want to change it to current date when a user clicks on it. I use the follow code but nothing is happening. Can...
1
by: skhairnar | last post by:
Hi All, I am trying to write a validation rule for DateTimePicker, which will prevent user from selecting saturday or sunday as a value. For this I have added an event handler with following code:...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I posted this about a month ago but didn't get any response, so I thought I'd rephrase it. I have a DateTimePicker set for Up/Down Time format (HH:mm:ss). The problem is that when I...
6
by: Kyote | last post by:
I'm using a DateTimePicker for date fields in an Access db Membership app. Some of the date fields are empty, meaning they haven't been filled out yet, or they cannot be. But when a record is read...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
7
by: jerald m | last post by:
Hi please anybody help me.. <script language="java" type="text/javascript" src="datetimepicker.js"> in the script i add src="datetimepicker.js". For combo box also i put some scripting for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.