Google Search

Google
 

Sunday, May 25, 2008

Video: How Do I: Format Data in Controls?

Presenter:Beth Massi


Visual Basic programmers will see how to format data in controls like the TextBox, MaskedTextBox and the DateTimePicker.

Click here to go to original video page


Minute 0

Hide my name is Beth Massey and welcome to the Windows forms or data video series in this video we re going to take a look at formatting options in our controls it s a good idea to present the user with a clear indication of what type of data is in a control for instance we always want a gay control to only accept values and date formats Visual Studio comes with many formatting options we can take advantage of an item to show you some today so I m not our order manager project open already as the application we been building in this video series and I just added a new form called forum eight and that s open now so we also been adding a bunch of data sets the application and I ve got one open here called orders data set and he just has order and order details so you want to do first here is I want to make the ship date drop and the text box I can show you some formatting options on the date and the text box so I m now going to distract us over as details on to
Minute 1

Armed and that will create some controls for us that we can manipulate the first control it might take a look at here is the order date date Time picker on the daytime picker has a property called format that allows us to specify how that data is displayed right now by default it s long format so it spells out the day of the week the month he and the that puts the numbers for the month and the year so I want to change is to short so that ll just display the day month year format and we can also take a look at minimum date and maximum date she can set these values so for instance that s a for maximum date gets one of pic today and for minimum date let s just pick say January 1 2000 okay so let s run this and show you how this formatting
Minute 2

Parks in the order date they say you can see we can actually add these individually sick as a stock options I can say 21 2000 five maybe they sell on that makes it easy to enter we can also drop us down and you ll see a calendar display can pick today and it automatically jump to today or you can click on the year and month here and you ll see that it zooms out to 2007 I can t go any further than April and noticed that I picked 2000 has armed and dates he only see like 2000 to 2007 selected here such a critical feature of this daytime picker and in its pay attention to the formatting was setting up to call said format are tech stocks so formatting text box is a little bit different because it can hold any type of data not just dates so doesn t have a format property instead according to
Minute 3

Burgoyne to expand its data bindings and Ravenna click on the advanced button here and that gives us the formatting advance binding dialog care and you can notice that we ve got no formatting specified that I could take a daytime here and you notice that we could specify the type in this area we can select a short or long formats in a variety of ways one of the nice thing here is we can also specify what they know value would look like to the user so we could save maybe for instance nine that means a lot more than no to a user or blank is given an indication that they have entered any data at all sorts give this a try to identify now you see that we got the ship date here but if I enters a new row you ll notice that there s not immediately haven t entered any data at all and it s got a call because its two way if we set a date for instance here and say say the record in
Minute 4

I ll say we go and specify none again and save the record if she will save an all back into the database we type none set recall so let s take a look at a couple more ways to format let s turn it over our order details as in detail announces put that down here at the bottom of the form and quickly I ll add another buying the navigator today so that we can scroll through our order details and others in the dock this down on the bottom and it will set its binding sewers to the details and tank so you notice if that price down County races up a little bit and let s take a look at before we format any of these values what that looks like COC that the price is just a raw format here we ve got a currency story and database and is just coming
Minute 5

It was a double here in pain so we want to format this is kind seeing our control as well so we just click on this text box in the go into the same area data binding chair in our advanced and then we can select currency right here even defaults to two decimal places so we can even specify a scientific notation a numeric or even custom formatting see can just enter your own custom formats listed as you complete control over how exactly you want your format to be settled to specify currency here okay now when we run it we ve got four dollars down here it s not easy it really is so let s see how we do this in codecs aren t ago into our forms code here and I m going to add some code to our forms will
Minute 6

Out so let s create a text box on the fly and added a binding and its formatting calling code here so them to dim up a new text box K Annenberg and I create a new binding came in and start specifying some parameters here the first thing is the property names are in a bind to the text property of the Xbox and the data sources are bindings are so that s order detail binding source here and we re going to find to the price field in our table and the next thing is whether or not the formatting is able the next parameter so where it s a gas formatting we want this to be formatted and when it updates the data source on validation meeting week job offer that validation will fire and then the binding will be update the data source so the next day we can specify is the null value you notice we specify the summit
Minute 7

Dialogues we can do that here is well thing done for instance and then the last thing you see is the format string so that s where we specified currency with two decimal places so that sets up the formatting how we want now all we need to do is add that to the data bindings and I d be and that s just what this text box on our forum say where we can see it say 25 left 10 and let s make it a little different color and then all we need to do now is add it to our forms controls okay so let s give this a try in a five and now you see it here in the corner we
Minute 8

At four dollars and it s formatted exactly how we want a date so we can do all of this in code so just to be clear on that comment is out for her next off and I decided make sure that you understand what will we did was we can specify this price and are advanced data bindings and formatting dialogs all I did was specify currency and two decimal places okay so formatting can be done either in the code or peer through the designer still in thing I want to show it is the mask text box so I m going to go over to my data sources again and we re going to just remove the ship dates as a text box and I want to drop on a mass text box so if you don t see a control inside of the list when you drop down on your own data sources window you can click customize and you can select any control you want here so
Minute 9

I want to select mass text box in movie dragged us over will get a mass text box and I want to set the mass change the way when a deal is that when you sit in the short date format now what this means is that the users will see this in the text box and so when they start typing but a clear indication of where the slashes are they won t have to type them themselves a pay so when we needed deal isn t specified at first and now we just need to go back up and specify the it underneath our data bindings on our advanced tags tab D format and the format is going to be in the form of a month day in the year every got such a format from a month day year in case of that s the trick so now we run this
Minute 10

To see that our ship date he is here and looks relatively the same acceptably blanked out the values you ll notice that the formatting is still there and it s giving us an indication of what we need to tie 02020203 tab off we get 2002 of the telly format controls and now we can t format controls in all sorts of ways and you can take a look at the formatting options by using the so he s in the masks with you look at the mask property you can see how you can format all sorts of values so the last thing I want to quickly show you is how to format values in a gray and that s pretty straightforward so I m just going to remove their details as details and prevented me drop this as a grade and so enemies to edit 70s columns
Minute 11

And Mrs remove these and only display the product and the quantity and the price okay so quickly on the just anchor this and stretch it out just a bit every government can see all LOL I do is allow to go back into any columns and price is going to need to be formatted as currency here and it s pretty easy to do that so what I m going to do is go to the column type in a search that text box which is by default in Denver Bennett ahead and select the default cell style and the default cell style is where we can specify the format and what we can do is you can just go ahead and click currency notice we have the same options for custom scientific daytime etc Sun is going to go ahead and specify to dazzle places
Minute 12

You that our price will be formatted as a currency value paint a get up so early is easy to format our values and the one he used even masks or at least formatting on her control so that our users have an easier time reading the data and entering the data so I d like to thank you for your time if you like to check out the Visual Basic developer Center will be posting updates these videos there please also check out the Visual Basic team blog and my blog for more information basic

No comments: