Advertisement
digemall

Custom Formatter Infragistics Ultragrid

Mar 9th, 2011
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3.     #region FORMATTER
  4.  
  5.     class AddSecs : IFormatProvider, ICustomFormatter
  6.     {
  7.         public object GetFormat(Type formatType)
  8.         {
  9.             if (formatType == typeof(ICustomFormatter))
  10.                 return this;
  11.             else
  12.                 return null;
  13.         }
  14.  
  15.         public string Format(string format, object arg, IFormatProvider formatProvider)
  16.         {
  17.             if (arg is int)
  18.             {
  19.                 return arg.ToString() + " SECS";
  20.             }
  21.             else
  22.                 throw new ArgumentException();
  23.         }
  24.     }
  25.  
  26.     #endregion
  27.  
  28.     public Form1()
  29.     {
  30.         InitializeComponent();
  31.         this.ultraGrid1.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(ultraGrid1_InitializeLayout);
  32.     }
  33.  
  34.     protected override void OnShown(EventArgs e)
  35.     {
  36.         base.OnShown(e);
  37.  
  38.         // fill the grid
  39.         Random rand = new Random();
  40.         DataTable dt = new DataTable();
  41.  
  42.         dt.Columns.Add("COLUMN_A", typeof(int));
  43.        
  44.         for (int i = 0; i < 20; i++)
  45.             dt.Rows.Add(rand.Next(1, 100));
  46.         dt.AcceptChanges();
  47.  
  48.         BindingSource src = new BindingSource(dt, null);
  49.  
  50.         this.ultraGrid1.DataSource = src;
  51.     }
  52.  
  53.     void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  54.     {
  55.         e.Layout.Bands[0].Columns[0].Format = "####";
  56.         e.Layout.Bands[0].Columns[0].FormatInfo = new AddSecs();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement