I have a RadGridView, depending of the grid type I need, I build dynamically each columns and each aggregate functions. Each time I build a grid, at least one decimal column exist. For othe aggregate functions than SUM, it work...
When I assign the ItemSource to the array of objects I receive from the back-end, I receive the following message: "Aucune méthode 'Sum' sur le type 'System.Linq.Enumerable' n'est compatible avec les arguments fournis."
xaml:
<
telerik:RadGridView x:Name="radGridViewList" Margin="5 0 5 5" Visibility="Visible" RowDetailsVisibilityMode="Collapsed" FrozenColumnCount="1"
RowIndicatorVisibility="Collapsed" IsReadOnly="True" AutoGenerateColumns="False" CanUserFreezeColumns="False" Grid.Row="3"
CanUserResizeColumns="True" ShowColumnFooters="True" ShowGroupFooters="True" SelectionMode="Extended" IsSynchronizedWithCurrentItem="True"> />
Code behind:
static public void SetColumns(RadGridView pGrid, ColumnDescriptor[] pColumnNames)
{
if (pColumnNames != null)
{
EnumerableAggregateFunctionBase aggFunc;
for (int iColumnIndex = 0; iColumnIndex < pColumnNames.Length; iColumnIndex++)
{
ColumnDescriptor oneName = pColumnNames[iColumnIndex];
GridViewDataColumn oneColumn = new Telerik.Windows.Controls.GridViewDataColumn();
oneColumn.Header = oneName.ColumnName;
//Apply proper column display format.
switch (oneName.Format.ToUpper())
{
case "$":
oneColumn.DataFormatString = "C2";
break;
case "D":
oneColumn.DataFormatString = "yyyy'-'MM'-'dd";
break;
case "H":
oneColumn.DataFormatString = "HH':'mm";
break;
case "DH":
oneColumn.DataFormatString = "yyyy'-'MM'-'dd' 'HH':'mm";
break;
}
oneColumn.Width = new GridViewLength(1, GridViewLengthUnitType.Star);
oneColumn.ShowFilterButton = true;
oneColumn.IsSortable = true;
oneColumn.IsFilterable = true;
oneColumn.DataMemberBinding = new Binding(string.Format("ElementCells[{0:D}]", iColumnIndex));
oneColumn.TextAlignment = (TextAlignment)oneName.TextAlignment;
oneColumn.HeaderTextAlignment = (TextAlignment)oneName.TextAlignment;
//Create proper aggregate functions.
if (oneName.Agregation != AgregationFunction.None)
{
aggFunc = null;
switch (oneName.Agregation)
{
case AgregationFunction.Average:
aggFunc = new AverageFunction()
{
Caption = LocGeneral.GetControlText("Average") + ": "
};
break;
case AgregationFunction.Count:
aggFunc = new CountFunction()
{
Caption = LocGeneral.GetControlText("Count") + ": "
};
break;
case AgregationFunction.FirstValue:
aggFunc = new FirstFunction()
{
Caption = LocGeneral.GetControlText("First") + ": "
};
break;
case AgregationFunction.LastValue:
aggFunc = new LastFunction()
{
Caption = LocGeneral.GetControlText("Last") + ": "
};
break;
case AgregationFunction.MaxValue:
aggFunc = new MaxFunction()
{
Caption = LocGeneral.GetControlText("Max") + ": "
};
break;
case AgregationFunction.MinValue:
aggFunc = new MinFunction()
{
Caption = LocGeneral.GetControlText("Min") + ": "
};
break;
case AgregationFunction.Sum:
aggFunc = new SumFunction()
{
Caption = LocGeneral.GetControlText("Sum") + ": ",
SourceFieldType = typeof(Decimal)
};
break;
}
//If aggregate function created, we add it to the column.
if (aggFunc != null)
{
oneColumn.AggregateFunctions.Add(aggFunc);
}
}
pGrid.Columns.Add(oneColumn);
}
}
}
using System;
using System.Diagnostics;
using System.Runtime.Serialization;
namespace com.christiegrp.Neuron.Client
{
[DataContract]
public class CompleteConfiguration : NeuronClientBase
{
#region Constructors.
public CompleteConfiguration(bool pReadFromDatabase)
: base(pReadFromDatabase)
{
}
#endregion
#region NeuronClientBase overrides.
protected override string getListBoxDisplay()
{
return Name;
}
protected override string[] getColumnNames()
{
switch (GuiLanguage)
{
case Languages.LanguageEn:
return new string[] { "Code", "Name", "Contents" };
case Languages.LanguageFr:
return new string[] { "Code", "Nom", "Contenu" };
}
return null;
}
protected override object[] getItems()
{
return new object[] { Code, Name, Contents };
}
protected override void copyFrom(NeuronClientBase pSource)
{
base.copyFrom(pSource);
CompleteConfiguration theSource = pSource as CompleteConfiguration;
if (theSource == null)
{
throw new ArgumentException(WrongArgumentType, "pSource");
}
Code = theSource.Code;
Name = theSource.Name;
Contents = theSource.Contents;
IsVisible = theSource.IsVisible;
}
#endregion
#region Properties from main table.
[DataMember]
public string Code
{
[DebuggerStepThrough]
get { return mCode; }
[DebuggerStepThrough]
set
{
if (mCode != value)
{
mCode = value;
NotifyOfPropertyChange("Code");
}
}
}
[DataMember]
public string Name
{
[DebuggerStepThrough]
get { return mName; }
[DebuggerStepThrough]
set
{
if (mName != value)
{
mName = value;
NotifyOfPropertyChange("Name");
}
}
}
[DataMember]
public string Contents
{
[DebuggerStepThrough]
get { return mContents; }
[DebuggerStepThrough]
set
{
if (mContents != value)
{
mContents = value;
NotifyOfPropertyChange("Contents");
}
}
}
[DataMember]
public bool IsVisible
{
[DebuggerStepThrough]
get { return mIsVisible; }
[DebuggerStepThrough]
set
{
if (mIsVisible != value)
{
mIsVisible = value;
NotifyOfPropertyChange("IsVisible");
}
}
}
#endregion
#region Private fields.
private string mCode;
private string mName;
private string mContents;
private bool mIsVisible;
#endregion
}
[DataContract]
public class ColumnDescriptor
{
[DataMember]
public string ColumnName { get; set; }
[DataMember]
public ColumnAlignment TextAlignment { get; set; }
[DataMember]
public AgregationFunction Agregation { get; set; }
[DataMember]
public int GroupingPosition { get; set; }
[DataMember]
public string Format { get; set; }
}
[DataContract]
public class ListElements
{
public ListElements()
{
ElementGuid = Guid.Empty;
ElementCells = null;
IsSelected = false;
}
[DataMember]
public Guid ElementGuid { get; set; }
[DataMember]
public object[] ElementCells { get; set; }
public bool IsSelected { get; set; }
}
public enum ListContext
{
PatientExams, ToBeBilledExamsPublic, NotTransmittedClaimsPublic, TransmittedClaimsPublic, PaidClaimsPublic, InErrorClaimsPublic, ToBeBilledExamsPrivate, NotTransmittedClaimsPrivate, TransmittedClaimsPrivate,
PaidClaimsPrivate, InErrorClaimsPrivate, NmbListContexts
}
public enum AgregationFunction
{
None, Average, MinValue, MaxValue, FirstValue, LastValue, Count, Sum, NmbAgregationFunction
}
public enum ColumnAlignment
{
Left, Right, Center
}
}