Results 1 to 4 of 4

Thread: [RESOLVED] format datagrid column to display only the time

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    83

    Resolved [RESOLVED] format datagrid column to display only the time

    Hi,

    I'm using compact framework with VS 2005.
    How can I format a datagrid column to display only the time.

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: format datagrid column to display only the time

    HI,
    For a time using your own date
    FormatDateTime(mydate, DateFormat.ShortTime)
    else
    FormatDateTime(Date.Now, DateFormat.ShortTime)
    for the current date.

    Is that what you mean?

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: format datagrid column to display only the time

    Did you follow the link I provided in your other thread? Question 44 on that page is "How do I format a date column in a datagrid?". It shows you how to set the format for a DataGridTextBoxColumn. Go to the MSDN library topic for the DataGridTextBoxColumn class and it has a code example for adding one to a grid. Look up "date formatting" or "time formatting" on MSDN and you'll find the format strings you can assign to the Format property of your DataGridTextBoxColumn.

    Many questions aren't going to be solved by finding a ready-made solution in one place. You have to construct a solution by breaking the problem into pieces and solving each piece on its own.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    83

    Re: format datagrid column to display only the time

    Yes I was able to solve the problem with some support from that link...

    Just for anyne who mght come across the same problem...you use tablestyles to format datagrid columns in compact framework apps.

    this example I came across might be useful.

    Code:
    private void Form1_Load(object sender, System.EventArgs e)
    		{
    			string dataTableName = "theTable";
    			//add a tablestyle to the grid so there will be custom columnstyles available
    			//    after the datasource has been set....
    			DataGridTableStyle ts = new DataGridTableStyle();
    			ts.MappingName = dataTableName;
    			
    			this.dataGrid1.TableStyles.Add(ts);
    			this.dataGrid1.DataSource = GetTheTable(dataTableName);
    			
    			//now default customcolumnstyles have been created, so we can use them to set properties
    			DataGridTextBoxColumn dgtbc;
    
    			//format the int
    			dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[0] as DataGridTextBoxColumn;
    			if(dgtbc != null)
    				dgtbc.Format = "n0"; 
    
    			//format the double
    			dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[1] as DataGridTextBoxColumn;
    			if(dgtbc != null)
    				dgtbc.Format = "f3"; // 0r "#.000"; 
    
    			//format the double as currency
    			dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[2] as DataGridTextBoxColumn;
    			if(dgtbc != null)
    				dgtbc.Format = "c4";  
    
    			//format the date
    			dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[3] as DataGridTextBoxColumn;
    			if(dgtbc != null)
    			{
    				dgtbc.Format = "t"; // t is for time. d is for date				dgtbc.Width = 100; //size it
    			}			
    
    		}
    Last edited by sunshine123; Jun 18th, 2007 at 10:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width