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
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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