In my datagrid I have a DateTime field which does not show the hours and minutes. Well at least it shows 00:00 but my the DateTime value can not be 00:00. I use this time format string "dd-MM-yyyy HH:mm".
When I show the DateTime value inside a popup it shows the hours and minutes (and seconds) so it can't be 00:00:
How can I force the datagrid to show the hours and minutes?
This is my code:
namespace DXWindowsApplication1
{
public partial class Form1 : XtraForm
{
public Form1()
{
InitializeComponent();
InitGrid();
}
BindingList<Message> gridDataList = new BindingList<Message>();
void InitGrid()
{
/*gridDataList.Add(new Message("joepie de poepie test \n joep meloen hallo \n mhooooo", "username", new DateTime(2008)));
gridDataList.Add(new Message("test message 2 \n kitkat android \n toktoktoktotktotktokt", "Pipo", new DateTime(2005)));
gridDataList.Add(new Message("test message 2 \n kitkat android \n toktoktoktotktotktokt", "Pipo", new DateTime(2006)));
gridDataList.Add(new Message("test message 2 \n kitkat android \n toktoktoktotktotktokt", "Pipo", new DateTime(2007)));*/
gridControl1.DataSource = gridDataList;
gridView1.ExpandAllGroups();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void simpleButton1_Click(object sender, EventArgs e)
{
gridDataList.Add(new Message(memoEdit1.Text, "username", DateTime.Now));
gridView1.ExpandAllGroups();
memoEdit1.Text = "";
}
}
}
This is the autogenerated code:
// colsendTime
//
this.colsendTime.AppearanceCell.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.colsendTime.AppearanceCell.Options.UseBackColor = true;
this.colsendTime.Caption = "Verzonden op";
this.colsendTime.DisplayFormat.FormatString = "dd-MM-yyyy HH:mm";
this.colsendTime.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
this.colsendTime.FieldName = "sendTime";
this.colsendTime.GroupFormat.FormatString = "dd-MM-yyyy HH:mm";
this.colsendTime.GroupFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
this.colsendTime.Name = "colsendTime";
this.colsendTime.OptionsColumn.ReadOnly = true;
this.colsendTime.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
this.colsendTime.Visible = true;
this.colsendTime.VisibleIndex = 2;
DateTime
values are automatically grouped as dates in XtraGrid, unless the column's GroupInterval
property is explicitely set to Value
.
This behavior is described in the DevExpress documentation on the ColumnGroupInterval
enumeration.
Side note: don't set UnboundType
property if you're not making any handling of CustomUnboundColumnData
.