在wpf datagrid中格式化DataGridDateTimeColumn?

时间:2015-01-15 09:19:52

标签: c# wpf datagrid

我正在处理数据网格并将其绑定在代码隐藏文件中,我在其中向数据网格提供数据表默认视图。 datagrid包含一个成功绑定的DataGridDateTimeColumn。

我需要在每个第1到第9行显示此DataGridDateTimeColumn,其中日期和时间值,而其余时间(每第10行)仅时间值。问题是,即使我只将时间值传递到第10行,然后还需要系统日期附加时间(我给出的时间)。我不知道这里有什么不对。

<c1:C1DataGrid ScrollMode="Deferred" Name="TabulerDataGrid" Visibility="Hidden"></c1:C1DataGrid>

这是C#代码:

private void BindDataGrid(object sender, EventArgs e)
{
    foreach (DataColumn col in dataCollection.Columns)
        {
            if (col.ColumnName == "Time")
            {
                C1.WPF.DataGrid.DataGridDateTimeColumn column = 
                    new C1.WPF.DataGrid.DataGridDateTimeColumn();

                column.Format = GlobalDataDisplay.DateFormat;  //TTP 6321
                column.FilterMemberPath = "OnlyDate";
                DataGridContentFilter f = new DataGridContentFilter();
                DataGridDateTimeFilter d = new DataGridDateTimeFilter();
                d.EditMode = C1DateTimePickerEditMode.DateTime;
                f.Content = d;
                column.Filter = f;
                column.CanUserFilter = true;
                column.Header = col.ColumnName;

               column.Binding = new System.Windows.Data.Binding {
                         Path = new PropertyPath(col.ColumnName), 
                    Converter = new ConvertDateChange()};

                TabulerDataGrid.Columns.Add(column);
            }
      }   
        TabulerDataGrid.ItemsSource = dataCollection.DefaultView; 

// time value is extracted from datacollection and provided to column.
foreach (C1.WPF.DataGrid.DataGridRow row in this.TabulerDataGrid.Rows.Where(x => x.Index % 10 == 0))
            {
               if (!string.IsNullOrEmpty(dateTime))
                {
                    DateTime dt = (DateTime)(row.DataItem as DataRowView)[0];
                    (row.DataItem as DataRowView)[0] = dt.ToString("HH:mm:ss");; 
                }
            }

}

0 个答案:

没有答案