Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My question is in regards to the textbox control. I want the users to type in a date format like this:

 

mm/dd/yyyy

 

I should be able to set the "picture" property of the textbox, but I dont see any. Right now, as it stands they can type in whatever they want. I want the screen to accept data in that format only, and have it be a valid date as well (not able to input 00/32/0000 or simular values)

 

 

 

Also, I do not want to use the date time picker, as the mouse is not a control on this application.

 

Any ideas?

www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
  • *Experts*
Posted

I don't understand your (two?) problems at all.....you seem to have mixed two totally unrelated problems into one sentence.

 

If you want to validate a date:

Try
 Date.Parse(theDate)
Catch
 'not a valid date
End Try

  • *Experts*
Posted

@Volte: I think he meant a mask, not a picture, though I was confused at first, too :)

 

@Drstein99: You can use the Mask Edit control for this, but I would think you'd really want the DateTimePicker, which support a nice dropdown calendar as well as providing built-in support for checking on valid dates.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I dont want a datetimepicker. The users of this application are used to a text based application, not accustomed to the mouse (as it stands), and there are many more issues. The base is: I cant use a datetimepicker.

 

 

 

I am not familiar with a mask edit control. If I had not made myself clear, I apologize: please allow me to reiterate:

 

I need(ed) a textbox control to accept a date IN ONLY this fashion - that would not allow users to type ANYTHING ELSE other than:

 

mm/dd/yyyy

 

AND validate the data, to make sure that users weren't typeing in month 00 or month 99 or day 40.

www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
  • *Experts*
Posted

Personally, I hate being forced into one exact format such as mm/dd/yyyy if I want to type m/d/yyyy (for instance). Granted, it's perfectly acceptable to reformat the m/d/yyyy to mm/dd/yyyy after the tab out (one option) to ensure the data matches a specific format. And I agree that data-entry forms should not require any mouse movement, or at least keep it to a minimum.

 

Having said that, the DateTimePicker still sounds perfect. You can set the format to "Custom" and the CustomFormat property to "MM/dd/yyyy" (note the capital M's - lowercase is for minute). That forces the format you want and yet they can still type exactly what they want (or less, if they like typeing "m/d/yyyy").

 

While you can look at the MaskEditBox, it's painful (in my opinion), and overkill for dates.

 

If you use a textbox, you have more control (you can try DateTime.Parse) since you can validate however you want and even convert values. For example, I've had projects in the past where we allow certain characters to be entered that get parsed into dates. For example, enter "t" in our special textbox and when you tab out it gets today's date (DateTime.Now.Date). Enter "y" and it gets yesterday's date. Enter a single number between -30 and 30 and it went that number of days in the past or future. It requires a more custom solution but gives more flexability.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...