DevExpress xtragrid datetime不显示小时和分钟

时间:2014-02-14 13:16:56

标签: c# datetime-format xtragrid

在我的数据网格中,我有一个DateTime字段,它不显示小时和分钟。好吧,至少它显示00:00,但我的DateTime值不能是00:00。我使用这个时间格式字符串" dd-MM-yyyy HH:mm"。

enter image description here

当我在弹出窗口中显示DateTime值时,它显示小时和分钟(和秒),因此它不能是00:00:

enter image description here

如何强制数据网格显示小时和分钟?

这是我的代码:

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 = "";
        }

    }
}

这是自动生成的代码:

            // 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;

2 个答案:

答案 0 :(得分:3)

除非将列的DateTime属性明确设置为GroupInterval,否则

Value值会自动在XtraGrid中分组为日期。

ColumnGroupInterval enumeration.

上的DevExpress文档中描述了此行为

附注:如果您未对UnboundType进行任何处理,请勿设置CustomUnboundColumnData属性。

答案 1 :(得分:0)

您可以使用RepositoryItemDateEdit在网格中显示时间并指定VistaEditTime = DevExpress.Utils.DefaultBoolean.True

E.g。

DevExpress.XtraEditors.Repository.RepositoryItemDateEdit oItem = New DevExpress.XtraEditors.Repository.RepositoryItemDateEdit();

oItem.DisplayFormat.FormatString = "dd-MM-yyyy HH:mm"
oItem.EditFormat.FormatString = "dd-MM-yyyy HH:mm"
oItem.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
this.colsendTime.ColumnEdit = oItem
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.Name = "colsendTime";
this.colsendTime.OptionsColumn.ReadOnly = true;
this.colsendTime.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
this.colsendTime.Visible = true;
this.colsendTime.VisibleIndex = 2;