Example #1
0
 /// <summary>
 /// Generate aspect getters and putters for any columns that are missing them (and for which we have
 /// enough information to actually generate a getter)
 /// </summary>
 protected virtual void CreateMissingAspectGettersAndPutters()
 {
     foreach (OLVColumn x in this.ListView.AllColumns)
     {
         OLVColumn column = x; // stack based variable accessible from closures
         if (column.AspectGetter == null && !String.IsNullOrEmpty(column.AspectName))
         {
             column.AspectGetter = delegate(object row)
             {
                 // In most cases, rows will be DataRowView objects
                 DataRowView drv = row as DataRowView;
                 if (drv == null)
                 {
                     return(column.GetAspectByName(row));
                 }
                 return((drv.Row.RowState == DataRowState.Detached) ? null : drv[column.AspectName]);
             };
         }
         if (column.IsEditable && column.AspectPutter == null && !String.IsNullOrEmpty(column.AspectName))
         {
             column.AspectPutter = delegate(object row, object newValue)
             {
                 // In most cases, rows will be DataRowView objects
                 DataRowView drv = row as DataRowView;
                 if (drv == null)
                 {
                     column.PutAspectByName(row, newValue);
                 }
                 else
                 {
                     if (drv.Row.RowState != DataRowState.Detached)
                     {
                         drv[column.AspectName] = newValue;
                     }
                 }
             };
         }
     }
 }
Example #2
0
 /// <summary>
 /// Generate aspect getters and putters for any columns that are missing them (and for which we have
 /// enough information to actually generate a getter)
 /// </summary>
 protected virtual void CreateMissingAspectGettersAndPutters()
 {
     for (int i = 0; i < this.Columns.Count; i++)
     {
         OLVColumn column = this.GetColumn(i);
         if (column.AspectGetter == null && !String.IsNullOrEmpty(column.AspectName))
         {
             column.AspectGetter = delegate(object row) {
                 // In most cases, rows will be DataRowView objects
                 DataRowView drv = row as DataRowView;
                 if (drv != null)
                 {
                     return(drv[column.AspectName]);
                 }
                 else
                 {
                     return(column.GetAspectByName(row));
                 }
             };
         }
         if (column.IsEditable && column.AspectPutter == null && !String.IsNullOrEmpty(column.AspectName))
         {
             column.AspectPutter = delegate(object row, object newValue) {
                 // In most cases, rows will be DataRowView objects
                 DataRowView drv = row as DataRowView;
                 if (drv != null)
                 {
                     drv[column.AspectName] = newValue;
                 }
                 else
                 {
                     column.PutAspectByName(row, newValue);
                 }
             };
         }
     }
 }