使用dotnetbar superGridControl 日期列显示格式
使用dotnetbar superGridControl控件时,遇到一个问题:对于是日期的列,默认的格式只显示日期,不显示时间。
在编辑其中没有找到设置日期显示格式的属性。
只在列设计器里找到了一个属性:RenderType
将 RenderType 设置为GridDateTimeInputEditControl 后,显示的格式依然不正确。
最后在代码中处理了一下,终于得到了想要的效果。
具体的实现流程:
- 在列编辑器中设置时间列的 RenderType 为GridDateTimeInputEditControl
- 在窗体的 load 事件中添加以下代码
//获取grid控件
GridPanel primaryGrid = superGridControl1.PrimaryGrid;
//获取要设置时间格式的列
var createTimeColumn = primaryGrid.Columns["CreateTime"];
//获取该列绑定的控件
GridDateTimeInputEditControl createTimeColumnRenderControl = (GridDateTimeInputEditControl)createTimeColumn.RenderControl;
//设置 format 为自定义
createTimeColumnRenderControl.Format = DevComponents.Editors.eDateTimePickerFormat.Custom;
//设置自定义格式
createTimeColumnRenderControl.CustomFormat = "yyyy-MM-dd HH:mm:ss";
//设置该列的AutoSizeMode
createTimeColumn.AutoSizeMode = ColumnAutoSizeMode.AllCells;