Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating windows application using c# 2010 - in my application i am using datagridview for billing purpose, i am create data grid view columns on page load event using DataGridViewTextBoxColumn, here i want how to display time on DataGridViewTextBoxColumn.

Give me any one some ideas.

What I have tried:

How to display time on using DataGridViewTextBoxColumn
Posted
Updated 29-Dec-16 21:59pm

1 solution

Convert the time to a string and set into the cell in the relevant column.
 
Share this answer
 
Comments
Boopalslm 30-Dec-16 4:06am    
This is my code but not working


DataGridViewTextBoxColumn dgvtime = new DataGridViewTextBoxColumn();
dgvtime.HeaderText = "Time";
dgvtime.Width = 125;
dataGridView1.Columns.Add(dgvtime);
dataGridView1.Columns[1].DefaultCellStyle.Format = "hh:mm:ss tt";

please give me some ideas.
Richard MacCutchan 30-Dec-16 4:28am    
What is "not working" supposed to tell us?
Boopalslm 30-Dec-16 4:40am    
now i got a error from last line

Object reference not set to an instance of an object.


DataGridViewTextBoxColumn dgvtime = new DataGridViewTextBoxColumn();
dgvtime.HeaderText = "DATED";
dgvtime.Width = 100;
dataGridView1.Columns.Add(dgvtime);
dataGridView1.Columns["DATED"].DefaultCellStyle.Format = @"hh\:mm";

please guide me.
Richard MacCutchan 30-Dec-16 5:02am    
There is no column named DATED in your collection. You really need to make better use of the documentation to correct simple errors like this. See DataGridViewColumnCollection.Item Property (String) (System.Windows.Forms)[^].
Boopalslm 30-Dec-16 5:10am    
how to declare DATED in my gridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900