Solved

I have a switch statement to compare a datagrid column type to a constant.  How do I assign a DateTime type to a constant.  I tried using type of but that is run time

Posted on 2010-08-25
1
233 Views
Last Modified: 2012-05-10
Please see attached code.  Constant declaration is not right because it is at runtime.
public const string cstrDateTime = typeof(System.DateTime).ToString();





switch (ColomnType)

                        {

                            case cstrInt:

                                // Output Integers as numbers

                                msoStyle = "";

                                break;



                            case cstrDateTime:

                                // Output dates as MM/dd/yyyy

                                msoStyle = "mso-number-format: mm\\/dd\\/yy";

                                break;



                            default:

                                // Output other values as string

                                msoStyle = "mso-number-format: \\@";

                                break;

                        }

Open in new window

0
Comment
Question by:MichBman
1 Comment
 
LVL 4

Accepted Solution

by:
thepanch earned 500 total points
ID: 33525058
object cstrDateTime = new DateTime(); //this line set the type DateTime to the object

            if (cstrDateTime.GetType().Name.ToString()=="DateTime") //compare the Type of the object
            MessageBox.Show(cstrDateTime.GetType().ToString()); //just do something if its true.

I hope it helps
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 3 38
Duplicate a row 2 33
index Out OF Range Exception error 4 31
VB.NET HttpWebRequest 12 32
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now