2017-11-10 10 views
0

私はInfragisitics 17.1 UltraGridを使用しています。Infragistics UltraGrid、文字列値から整形された文字列が必要です

グリッドには2つの列があります。

次のように、2番目の列の書式設定された文字列が必要です。

「20170102123456」=>「2017年1月2日12時34分五十六秒"

第二のカラムのデータ型は『文字列』ではない『日付』。

このグリッドは巨大になりますデータなので、任意の変換は私に心配である。

しかし、どのadiveは大歓迎です。

DataSoureすぐ下のような。

private void SetTestData() 
    { 
     DataTable dtDataSource = new DataTable("table1"); 
     dtDataSource.Columns.Add("OrderDate", typeof(DateTime)); 
     dtDataSource.Columns.Add("RequiredDate", typeof(string)); 
     ultraGrid1.DataSource = dtDataSource; 

     DataRow rowNew = dtDataSource.NewRow(); 
     rowNew["OrderDate"] = DateTime.Now; 
     rowNew["RequiredDate"] = "20170101123456"; 
     dtDataSource.Rows.Add(rowNew); 
    } 

そして、私はただ、下記のようなグリッドを初期化し、

private void UltraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) 
    { 
     // Fit columns 
     e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn; 

     // Set date formats 
     e.Layout.Bands[0].Columns["OrderDate"].Format = "yyyy-MM-dd HH:mm:ss"; 
     e.Layout.Bands[0].Columns["RequiredDate"].Format = "yyyy-MM-dd HH:mm:ss"; 
    } 

最初の列が正常に動作しますが、2番目の列にはありません。

2番目の列を次のように表示するにはどうすればよいですか?

「20170102123456」=>「2017年1月2日12時34分五十六秒"

+0

DateTimeの値を割り当てて –

+0

ええ。その通り。しかし、私は変換する文字列の値が必要です。私はあまりにも多くのデータを持っているので、私は変換のコストについて心配しています。 – Jake

答えて

0

のUltraGridは、あなたがこの特定のケースで何ができるか。これだけで会話を行うことができなくなりますが、独自のカスタムを実装しているIEditorDataFilter 。したがって、このようなあなたのInitializeLayuotを変更しますするには:

private void UltraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) 
{ 
    // Fit columns 
    e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn; 

    // Set date formats 
    e.Layout.Bands[0].Columns["OrderDate"].Format = "yyyy-MM-dd HH:mm:ss"; 

    // You do not need this as the column data type is string 
    //e.Layout.Bands[0].Columns["RequiredDate"].Format = "yyyy-MM-dd HH:mm:ss"; 

    // Set the column's editor DataFilter instead 
    e.Layout.Bands[0].Columns["RequiredDate"].Editor.DataFilter = new DF(); 
} 

次に、このようにカスタムDataFilterを作成:2番目の列は型である `それ作るSTRING`ので

internal class DF : IEditorDataFilter 
{ 
    public object Convert(EditorDataFilterConvertArgs conversionArgs) 
    { 
     switch(conversionArgs.Direction) 
     { 
      case ConversionDirection.DisplayToEditor: 
       break; 
      case ConversionDirection.EditorToDisplay: 
       var valueAsString = conversionArgs.Value.ToString(); 
       var year = int.Parse(valueAsString.Substring(0, 4)); 
       var month = int.Parse(valueAsString.Substring(4, 2)); 
       var day = int.Parse(valueAsString.Substring(6, 2)); 
       var hours = int.Parse(valueAsString.Substring(8, 2)); 
       var minutes = int.Parse(valueAsString.Substring(10, 2)); 
       var result = new DateTime(year, month, day, hours, minutes, 0).ToString("yyyy-MM-dd HH:mm:ss"); 

       conversionArgs.Handled = true; 
       conversionArgs.IsValid = true; 
       return result; 
      case ConversionDirection.OwnerToEditor: 
       break; 
      case ConversionDirection.EditorToOwner: 
       break; 
      default: 
       break; 
     } 

     return conversionArgs.Value; 
    } 
} 
+0

再生いただきありがとうございます。 私はほとんどそれをあきらめています。私は明日の夕方にそれをチェックします。 – Jake

関連する問題