2011-03-09 2 views
0

WinGrid (Infragistics, 알고 있어야하는 경우)에 int을 포함하는 열이 있습니다. 값은 시간을 계산할 수있는 시간 (초)입니다. IFormatProvider/ICustomFormatter를 만들었습니다. 내 표 초기화 중에 Format 및 FormatInfo 매개 변수를 설정합니다.GetFormat IFormatProvider 형식을 절대로 가져옵니다.

그러나 GetFormat이 사용자 지정 형식 포매터에서 호출 될 때 형식 매개 변수는 항상 NumberFormatInfo이며 ICustomFormatter는 아닙니다. 왜?

다음은 그것이 도움이 될 수 있도록 제 수업입니다.

public class SecToTime : IFormatProvider, ICustomFormatter 
{ 
    public object GetFormat(Type formatType) 
    { 
     if (formatType == typeof(ICustomFormatter)) 
     { 
      return this; 
     } 
     else 
     { 
      return null; 
     } 
    } 

    public string Format(string format, object arg, IFormatProvider provider) 
    { 
     if (arg is int) 
     { 
      int seconds = (int)arg; 
      int hours = (int)Math.Truncate((double)seconds/3600); 
      int minutes = (int)Math.Truncate((double)(seconds/60) % 60); 
      seconds = seconds % 60; 
      return string.Format("{0:hh:mm:ss}", new DateTime(0, 0, 0, hours, minutes, seconds)); 
     } 
     else 
      throw new ArgumentNullException(); 
    } 
} 

답변

0

:

FormatInfo가 호출되지 않습니다 Format 속성이없는 한 다음

할 경우에 도움이, 내 클래스 또한 세트. 그게 내가 할 수있는 유일한 이유 야. 왜 그렇게 부르지 않을지 생각해.

출처 : this Infragistics forum's post

는, 테스트 뭔가에 열 Format 속성을 설정하려고 ... :)

+0

그것은 무언가로 설정합니다. 다른 것들을 시도했지만 GetFormat이받는 형식 매개 변수를 변경하지 않는 것 같습니다. – Tipx

+0

Strange ... 기본 데이터 소스는 DataTable입니까? 그렇다면 해당 dataTable 열의 유형이 'int'로 설정되어 있습니까? – digEmAll

+0

기본 데이터 소스는 바인딩 소스이며 바인딩 소스의 데이터 소스는 데이터 테이블입니다. 내 column.DataType은 Int32입니다. – Tipx