I was wondering is it possible to disable selected dates in a DateTimePicker, so that user cannot select them. i know its possible in web forms but in windows forms im unable to do this.how can i achieve this.
The ease with which you can do this will depend on the dates you want to restrict. For instance, if you all you want to do is specify a range of valid dates to pick, then you can use the MinDate and MaxDate properties to set the bounds. If however, you want to cherry pick certain days within a range (for instance, no weekends), there is no built in method for doing this.
You could either find a third party control with this functionality, or you could try to hack it a bit by adding an event handler to the ValueChanged event, and forcing the current date time to the last value (which you'd have to cache) if they user picked something that was illegal according to your business logic... but this is a less than ideal way to do it.
Developer Express controls are usually very flexible and judging from this support article you can achieve what you want to do with their DateEdit control.
The control collection can be obtained from the following location: Over 60 Free Controls from DevExpress. (the free offer is no longer available)
Don't forget to read the EULA.
Related
I have recently been tasked with learning EF 6 and web forms scaffolding for our group. Most everything works perfect for me and even though I was ready to hate it I don't. There are a couple of things that I can not make work the way that I want them to. When I scaffold some CRUD pages it works great, but I want to set some default values on the Insert page. I am able to set values in the constructor or the properties, but they do not go to the insert page until the click event to add the item. I have tried every way I could think to figure out an annotation that would work on my object as well as in the Dynamic control. So far I can not make anything work. I can actually remove the dynamic control and add my own control and add it to the object in the insert method, but that just does not feel right. Is there another way of doing this?
Specifically the things that I am trying to do are to set a default date in some fields based on DateTime values over a 30 day period from creation time. I also have state and county dropdowns that are tied to more than just the object that I am working on. Currently I use EF6 and LINQ in my DAL to just populate the dropdowns with objectdatasources and they work great. I want to hook them as dynamic controls as well. I know I need the [DataType] attribute, but there is no dropdown option to choose from. Also I am not sure how to hook up the dropdowns to have the county fire after the state fires so that the counties will change with each state selection. Is there a tutorial somewhere that would cover these things. I have searched everywhere and can not find any guidance.
Thanks Jimmy
Since no one seems to know the answer I thought I would list the needed things to help you if you are having the same issues. If you need to work with the data inside a Dynamic control you are going to have to do a lot of conversions. You must find the Dynamic control in the container you are using and parse that to a dynamic control and then you need to dig into the control template of that control and find the textbox etc that you need and parse that into the needed control type and grab or set its value. If you are needing to keep your code secure and must pass Fortify or some other static analysis tool you will also have to encode the values because fortify can not see that it came from a control that was encoded. This becomes a pain in the butt and it is much easier just to go ahead and switch to a standard control and manually add that in the insert.
The line of code if you need to know how this would work is something like this.
((TextBox)(DynamicControl)fvName.FindControl("DynamicID").TemplateControl.FindControl("TextBox1")).Text;
I wrote this from hand so it might have something out of place, but this should get you on track.
Jimmy
According to this post, there's a separate DatePicker control in .net 4. I've tried it, and I don't see a good way to also let it select the time of the day.
Is there an easy way to transform DatePicker into DateTimePicker by editing XAML template? If not, what is the best way to get a DateTimePicker for WPF 4.0?
Extended WPF Toolkit sports a nice DateTimePicker with time of day.
There is also an article over on CP where someone created a control that works like the Winforms one... A WPF DateTimePicker That Works Like the One in Winforms
There isn't one without making it yourself or using a 3rd party control. However there is one within winforms if you want a quick fix that doesn't support data binding...
xmlns:window="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
<window:WindowsFormsHost >
<wf:DateTimePicker Format="Time" ></wf:DateTimePicker>
</window:WindowsFormsHost>
Just a time picker, but could easily be paired with a datepicker. You also need a reference to WindowsFormsIntegration and System.Windows.Forms.
Try the DateTimePicker in the extended WPF toolkit.
If you do want an DateTimePicker without external controls and also for commercial use, I've improved an existing one and share it here:
https://gist.github.com/Apflkuacha/406e755c8b42a70b7ab138e6b985bcdf
It will look like this, a field which shows the selected date&time and a popup window to select the date and time:
I'm using a Wizard in my ASP.NET page, where in the first step the user chooses from a DropDownList, how many sets of controls will appear in the next wizard step (from 1-5).
For example, in the 2nd step of the wizard there are 3 textboxes. If they choose 2 on the previous screen, there will be 6 as there will be 2 sets of these.
I need to be able to store the contents of all these textboxes in a database (simple part I think, there's 5 columns and all can be null.
The easy way of doing this I think is just creating all of the possible controls (5 sets), and hiding them based on what they choose in the previous screen. Is there a more efficient/easier way?
Thanks
It really depends on your definition of efficient/easier.
A more standard approach would be to use a repeater control to display the correct number of controls based on previous input. However if you have not used a repeater control before there will be a degree of learning involved in displaying your output and retrieving user input during the postback.
You can use the ASP.NET Wizard Control
If you absolutely know that 5 boxes is the max, and it is highly unlikely that there would ever be more than that, using Control.Visible on the server controls and their interface items such as label or what ever else, would work... but...
It's a bit brittle of a solution, though; Requiring you to make manual code changes in a few places if you decide to add more possible boxes.
A dynamic solution would let you set a maximum number of options in config, or just a single place in code. It would probably require you to change your database structure a little bit, but that would likely be better for normalization, anyway. It involves dynamically generating the items in the step of the wizard, too.
(More info on that option can be had if desired!)
I'm working on a media library mock-up and I have a database of songs (over 9,000 tracks) that I want to display and make sortable. I'm not sure which GUI control would be best to use and I am not sure how it would be best to add all of the entries to the control.
Obviously using a listview and adding each entry one at a time takes a long time. Currently, the database is returning all of the tracks in an array of media objects (mediaEntry[] - a struct I defined). I don't know much about .NET's databinding system and any performance benefit that may bring.
The database is also searchable so I'll be changing the information displayed in the GUI control depending on the search terms.
Something like DataGridView or ListView in "virtual mode" should work well; this avoids the need to process all the data up-front.
however - I doubt that mediaEntry should be a struct - sounds like a class to me.
It is very rare you write a struct in .NET
The Listview control has a virtual mode, where you supply the viewable data on demand. Its actually easier to use than it sounds. Checkout the VirtualMode property and the RetrieveVirtualItem event.
You may want to give ObjectListView a try. It's very handy to use and has excellent performance when used appropriately.
Note: I'm not the developer of this library, I'm advertising it just because I used it in one of my projects.
When does the OnValidate event fire in the life-cycle of a control?
I'm creating a DateBox that will allow the user to enter a date in MM/DD/YYYY format (text) and need to verify that the date is in that format. It'll never be converted to a date (stored as string) but I would like to know the best time to validate that data (and provide feedback).
Note: It may seem a bit like re-inventing the wheel, but the app that I'm writing gets deployed to a tablet-pc and the winforms DateTimePicker is hell to edit with a stylus and my users just want to be able to write in the date.
MaskedTextBox Control might help you.
OnValidate happens after the Loading events (source)
You should validate on the client-side (javascript) AND server side either using the OnValidate or when handling the submission of the form (or both).