This is part #2 of a series of tutorial focusing on how to generate Excel document from C# with late binding technique. Note that my WordPress theme is not code friendly, so my apologize in advance.
This is part #1 of a series of tutorial focusing on how to generate Excel document from C# with late binding technique. Note that my WordPress theme is not code friendly, so my apologize in advance.
I Don’t get the hatred around global variable in programming world. There are tons of articles in the net explaining why programmer must stay away from it. Well I’ve been programming for about ten years, yet I found global variable is really a gift.
Most of the reasoning behind the hatred is code maintainability. That is kind of ridiculous, a well written code will be easy to maintain, and badly written one will be hard to maintain regardless of global variable usage.
From what I saw, Microsoft Surface could be a fresh air for .NET platform and its programmers. If its a success, then we’ll see more .NET programmers works on tablet and touch applications, which means business will get more advantage of matured Microsoft systems.
For you whom does not like to read, short answer for the problem is: use Value property, instead of Text property.
And now, the story behind this:
I uses DateTimePicker as placeholder for date value in my applications and I uses the Text property because the input and return value is string – no need to do casting – and the text will be formatted accordingly to DateTimePicker.Format property. And if you set the the Text property with the correct format, then the Value property will also updates, very convenient because this way you don’t need to worry about the regional setting on user’s machine.
But it has one behavior that I don’t really like, that is if you set the Text property, it won’t update before the DateTimePicker is drawn. Strangely, and fortunately, the Value property will updated anyway.
See this sample code :
Form FORM = new Form;
DateTimePicker DTP = new DateTimePicker();
DTP.Parent = FORM;
DTP.Format = DateTimePickerFormat.Custom;
DTP.CustomFormat = “dd/MM/yyyy”;
DTP.Text = “06/07/2012”; //set DTP value to July, 6th 2012
MessageBox.Show(DTP.Text); //the text in messagebox is empty string
MessageBox.Show(DTP.Value.ToString(“dd/MM/yyyy”) ; //text in messagebox is 06/07/2012 !!
MessageBox.Show(DTP.Text) ;//the text in messagebox is 06/07/2012
MessageBox.Show(DTP.Value.ToString(“dd/MM/yyyy”) ; //text in messagebox is 06/07/2012
So what’s the deal? Well, sometimes users don’t need to view the form containing the particular DateTimePicker instead they only need to view the date for work efficiency reason. This is a very big deal if your application is being used intensively. So in this kind of scenario, you can use the Value property to get the date, but remember, you need to cast it to string and apply the correct format.
Thanks for reading up to this line, leave comments if you don’t mind.
I really like using .NET DataGridView because its relatively simple and clean.
However, some behavior is a bit confusing for a beginner coder like me.
One of the confusions is the cell styling. DataGridView offers some comprehensive styling but it has one limitation that is not well documented. For reason unknown to me, DataGridView – which has DataTable bound to it – will not apply some cell styles if it’s not visible.
I guess I’m a bit old now that I cannot remember almost half of my computer knowledge. So now I decide to write things that I still can remember before they gone with the wind. And now I’ll write about BASIC computer programming. It’s a bit of old school, but I thing it can help you if you just starting to learn about computer programming.
Ok, I think everybody know that “Programmer” is someone who creates computer programs – also known as “software”. If you read up to this point, you might get interested to be a programmer, so I’ll try my best to guide you to be one. But, before we start creating a computer program we need to know more about programming it self. Continue reading