or
Hi,
I am using Rad Controls for WPF Q2 of 2013, Also I am new to Telerik.
I would like to create 2 rows for a single record in the telerik rad grid view as attached. Is it possible to do the template in the XAML code itself ?
With Regards.
Siva
Hi,
I am using Rad Controls for WPF Q2 of 2013, Also I am new to Telerik.
I would like to create 2 rows for a single record in the telerik rad grid view as attached. Is it possible to do the template in the XAML code itself ?
With Regards.
Siva
<
telerik:RadBusyIndicator
Name
=
"busyInd"
HorizontalAlignment
=
"Left"
Grid.Row
=
"1"
Margin
=
"10,10,0,0"
VerticalAlignment
=
"Top"
Height
=
"255"
Width
=
"372"
IsIndeterminate
=
"True"
>
<
telerik:RadCartesianChart
x:Name
=
"CartesianChartDemo"
Grid.Column
=
"5"
Margin
=
"10"
Grid.Row
=
"2"
Grid.ColumnSpan
=
"3"
>
<
telerik:RadCartesianChart.Behaviors
>
<
telerik:ChartPanAndZoomBehavior
PanMode
=
"Both"
ZoomMode
=
"Both"
/>
</
telerik:RadCartesianChart.Behaviors
>
</
telerik:RadCartesianChart
>
</
telerik:RadBusyIndicator
>
CartesianChartDemo.VerticalAxis =
new
CategoricalAxis();
CartesianChartDemo.HorizontalAxis =
new
LinearAxis();
CartesianChartDemo.Grid =
new
CartesianChartGrid() { MajorLinesVisibility = GridLineVisibility.XY };
string
strQuery =
"MyQuery"
;
//Function to get datatable
DataTable dtAlloys = DataRetriever.GetDataTable(strQuery);
BarSeries barSer =
new
BarSeries();
barSer.ShowLabels =
true
;
barSer.CombineMode = ChartSeriesCombineMode.Cluster;
BarSeries barSer2 =
new
BarSeries();
barSer2.ShowLabels =
true
;
barSer2.CombineMode = ChartSeriesCombineMode.Cluster;
foreach
(DataRow drAlloy
in
dtAlloys.Rows)
{
barSer.DataPoints.Add(
new
CategoricalDataPoint() { Category = drAlloy[
"MATERIAL_CODE"
], Label =
string
.Format(
"{0:N}"
, drAlloy[
"WT"
]), Value =
double
.Parse(drAlloy[
"WT"
].ToString()) });
barSer2.DataPoints.Add(
new
CategoricalDataPoint() { Category = drAlloy[
"MATERIAL_CODE"
], Label =
string
.Format(
"{0:N}"
, drAlloy[
"TARG"
]), Value =
double
.Parse(drAlloy[
"TARG"
].ToString()) });
}
CartesianChartDemo.Series.Clear();
CartesianChartDemo.Series.Add(barSer);
CartesianChartDemo.Series.Add(barSer2);
busyInd.IsBusy =
true
;
//Code to load data
busyInd.IsBusy =
false
;
public
MainWindow()
{
InitializeComponent();
IList<DataHeader> headerList = DataService.Instance.HeaderList;
for
(
int
i = 0; i < headerList.Count; i++)
{
DataHeader curentHeader = headerList[i];
GridViewBoundColumnBase column;
if
(curentHeader.Name ==
"AMOUNT"
)
{
column =
new
CGridViewNumColumn();
}
else
{
column =
new
GridViewDataColumn();
}
column.DataMemberBinding =
new
Binding(
"DataItemList["
+ i +
"]"
)
{
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
};
column.Header = curentHeader.Caption;
column.UniqueName = curentHeader.Name;
GridControl.Columns.Add(column);
}
DataContext = DataService.Instance.Data;
}
internal
class
CGridViewNumColumn : GridViewBoundColumnBase
{
public
override
FrameworkElement CreateCellEditElement(GridViewCell cell,
object
dataItem)
{
BindingTarget = RadMaskedTextInput.ValueProperty;
var input =
new
RadMaskedTextInput
{
HorizontalContentAlignment = HorizontalAlignment.Right,
Culture = CultureInfo.GetCultureInfo(
"en-GB"
),
FormatString =
"n2"
,
Mask =
""
,
MinWidth = 100,
SelectionOnFocus = SelectionOnFocus.SelectAll
};
input.SetBinding(BindingTarget, CreateValueBinding());
input.LostFocus += InputOnLostFocus;
return
input;
}
private
void
InputOnLostFocus(
object
sender, RoutedEventArgs routedEventArgs)
{
var input = sender
as
RadMaskedTextInput;
if
(input ==
null
)
throw
new
ArgumentNullException(
"sender"
);
if
(
string
.IsNullOrWhiteSpace(input.Value))
{
input.Value =
string
.Empty;
return
;
}
double
value;
//Format the number for frontend.
const
NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands;
if
(!
double
.TryParse(input.Value, style, input.Culture,
out
value))
{
input.Value =
"0"
;
}
input.Text = value.ToString(input.FormatString, input.Culture);
//Format the number for back-end. Extra precisions will be removed.
if
(!
double
.TryParse(input.Text, style, input.Culture,
out
value))
{
input.Value =
"0"
;
}
input.Value = value.ToString(input.Culture);
}
private
Binding CreateValueBinding()
{
var valueBinding =
new
Binding
{
Mode = BindingMode.TwoWay,
NotifyOnValidationError =
true
,
ValidatesOnExceptions =
true
,
Path =
new
PropertyPath(DataMemberBinding.Path.Path)
};
return
valueBinding;
}
}
public
abstract
class
IBacktestOption
{
#region fields
private
double
mGearing;
public
double
Gearing {
get
{
return
mGearing; }
set
{ mGearing = value; } }
private
double
? mGlobalCap;
public
double
? GlobalCap {
get
{
return
mGlobalCap; }
set
{ mGlobalCap = value; } }
private
double
? mGlobalFloor;
public
double
? GlobalFloor {
get
{
return
mGlobalFloor; }
set
{ mGlobalFloor = value; } }
public
string
Nom {
get
;
set
; }
#endregion
protected
IBacktestOption(
double
aGearing,
double
? aGlobalCap,
double
? aGlobalFloor)
{
Gearing = aGearing;
GlobalCap = aGlobalCap;
GlobalFloor = aGlobalFloor;
}
public
abstract
Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest);
public
abstract
bool
CheckOption();
}
class
OptionCall : IBacktestOption, IEditableObject, INotifyPropertyChanged
{
#region fields
private
double
mStrike;
public
double
Strike {
get
{
return
mStrike; }
set
{ mStrike = value; } }
OptionCallData backupOptParamData;
private
int
mID;
public
struct
OptionCallData
{
internal
int
ID;
internal
double
Strike;
internal
double
? CapGlobal;
internal
double
? FloorGlobal;
internal
double
Gearing;
}
public
int
ID
{
get
{
return
mID; }
}
#endregion Fields
#region constructors
public
static
OptionCall CreateNewOptionCall(
double
strike,
double
gearing = 1,
double
? cap =
null
,
double
? floor =
null
)
{
return
new
OptionCall(strike,gearing,cap,floor);
}
public
OptionCall(
double
strike,
double
gearing = 1,
double
? cap =
null
,
double
? floor =
null
) :
base
(gearing,cap,floor)
{
Strike = strike;
Nom =
"Call"
;
}
#endregion
public
override
Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest)
{
/* ... */
}
public
override
bool
CheckOption()
{
return
true
;
}
#region Edition
public
void
BeginEdit()
{
}
public
void
CancelEdit()
{
mStrike =
this
.backupOptParamData.Strike;
GlobalCap =
this
.backupOptParamData.CapGlobal;
GlobalFloor =
this
.backupOptParamData.FloorGlobal;
Gearing =
this
.backupOptParamData.Gearing;
}
public
void
EndEdit()
{
this
.backupOptParamData.Strike = mStrike;
this
.backupOptParamData.CapGlobal = GlobalCap;
this
.backupOptParamData.FloorGlobal = GlobalFloor;
this
.backupOptParamData.Gearing = Gearing;
}
#endregion Edition
#region Events
public
event
PropertyChangedEventHandler PropertyChanged;
private
void
NotifyPropertyChanged(
string
info)
{
if
(PropertyChanged !=
null
)
PropertyChanged(
this
,
new
PropertyChangedEventArgs(info));
}
#endregion Events
}
class
CallSpread : IBacktestOption, IEditableObject, INotifyPropertyChanged
{
#region fields
private
double
mStrike1;
public
double
Strike1 {
get
{
return
mStrike1; }
set
{ mStrike1 = value; } }
private
double
mStrike2;
public
double
Strike2 {
get
{
return
mStrike2; }
set
{ mStrike2 = value; } }
OptionCallData backupOptParamData;
private
int
mID;
public
struct
OptionCallData
{
internal
int
ID;
internal
double
Strike1;
internal
double
Strike2;
internal
double
? CapGlobal;
internal
double
? FloorGlobal;
internal
double
Gearing;
}
public
int
ID
{
get
{
return
mID; }
}
#endregion Fields
#region constructors
public
static
CallSpread CreateNewCallSpread(
double
strike1,
double
strike2,
double
gearing = 1,
double
? cap =
null
,
double
? floor =
null
)
{
return
new
CallSpread(strike1, strike2, gearing, cap, floor);
}
public
CallSpread(
double
strike1,
double
strike2,
double
gearing = 1,
double
? cap =
null
,
double
? floor =
null
) :
base
(gearing,cap,floor)
{
Strike1 = Math.Min(strike1, strike2);
Strike2 = Math.Max(strike1, strike2);
Nom =
"Call Spread"
;
}
#endregion
public
override
Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest)
{
/* ... */
}
public
override
bool
CheckOption()
{
return
true
;
}
#region Edition
public
void
BeginEdit()
{
}
public
void
CancelEdit()
{
mStrike1 =
this
.backupOptParamData.Strike1;
mStrike2 =
this
.backupOptParamData.Strike2;
GlobalCap =
this
.backupOptParamData.CapGlobal;
GlobalFloor =
this
.backupOptParamData.FloorGlobal;
Gearing =
this
.backupOptParamData.Gearing;
}
public
void
EndEdit()
{
this
.backupOptParamData.Strike1 = mStrike1;
this
.backupOptParamData.Strike2 = mStrike2;
this
.backupOptParamData.CapGlobal = GlobalCap;
this
.backupOptParamData.FloorGlobal = GlobalFloor;
this
.backupOptParamData.Gearing = Gearing;
}
#endregion Edition
#region Events
public
event
PropertyChangedEventHandler PropertyChanged;
private
void
NotifyPropertyChanged(
string
info)
{
if
(PropertyChanged !=
null
)
PropertyChanged(
this
,
new
PropertyChangedEventArgs(info));
}
#endregion Events
}
<
telerik:RadDataForm
Grid.Column
=
"1"
Margin
=
"12,0,6,21"
Grid.ColumnSpan
=
"2"
HorizontalContentAlignment
=
"Stretch"
VerticalContentAlignment
=
"Stretch"
ItemsSource
=
"{Binding BacktestOpt}"
CommandButtonsVisibility
=
"Cancel,Commit,Edit,Navigation"
Grid.Row
=
"1"
Height
=
"456"
Grid.RowSpan
=
"2"
/>
private
ViList<IBacktestOption> mBacktestOpt;
public
ViList<IBacktestOption> BacktestOpt
{
get
{
if
(mBacktestOpt ==
null
&& Formule == 0)
{
ViList<IBacktestOption> newBacktestOpt =
new
ViList<IBacktestOption>();
newBacktestOpt.Add(Creators.CreateNewOptionCall(0));
this
.mBacktestOpt =
new
ViList<IBacktestOption>(newBacktestOpt);
Formule = PayoffFormule.CALL;
}
return
mBacktestOpt;
}
set
{
mBacktestOpt = value;
OnPropertyChanged(
"BacktestOpt"
);
}
}
private
PayoffFormule mFormule;
public
PayoffFormule Formule
{
get
{
return
mFormule; }
set
{
mFormule = value;
switch
(mFormule)
{
case
PayoffFormule.CALL :
Backtest.Option = Creators.CreateNewOptionCall(0);
break
;
case
PayoffFormule.PUT :
Backtest.Option = Creators.CreateNewOptionPut(0);
break
;
case
PayoffFormule.ASIAN_CALL:
Backtest.Option = Creators.CreateNewAsianCall(0);
break
;
case
PayoffFormule.ASIAN_PUT:
Backtest.Option = Creators.CreateNewAsianPut(0);
break
;
case
PayoffFormule.CALL_SPREAD:
Backtest.Option = Creators.CreateNewCallSpread(0,0.15);
break
;
default
:
break
;
}
BacktestOpt.Add(Backtest.Option);
OnPropertyChanged(
"BacktestOpt"
);
OnPropertyChanged(
"Formule"
);
}
}
private
PayoffFormule mFormule;
public
PayoffFormule Formule
{
get
{
return
mFormule; }
set
{
mFormule = value;
BacktestOpt.RemoveAt(0);
switch
(mFormule)
{
case
PayoffFormule.CALL :
Backtest.Option = Creators.CreateNewOptionCall(0);
break
;
case
PayoffFormule.PUT :
Backtest.Option = Creators.CreateNewOptionPut(0);
break
;
case
PayoffFormule.ASIAN_CALL:
Backtest.Option = Creators.CreateNewAsianCall(0);
break
;
case
PayoffFormule.ASIAN_PUT:
Backtest.Option = Creators.CreateNewAsianPut(0);
break
;
case
PayoffFormule.CALL_SPREAD:
Backtest.Option = Creators.CreateNewCallSpread(0,0.15);
break
;
default
:
break
;
}
BacktestOpt.Add(Backtest.Option);
OnPropertyChanged(
"BacktestOpt"
);
OnPropertyChanged(
"Formule"
);
}
}
GridViewDataColumn col =
new
GridViewDataColumn();
col.Header = column.Name;
col.DataMemberBinding = binding;
col.DataType = column.DataType;
col.IsSortable =
true
;
if
(column.DataType ==
typeof
(Int64))
{
col.DataMemberBinding.Converter =
new
LongConverter();
}
public
class
LongConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
//Int64? convertedValue = (Int64)value;
//if (convertedValue.HasValue)
//{
// return convertedValue.Value;
//}
//else
//{
// return "";
//}
return
"N/A"
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
if
(value.ToString().ToUpper() ==
string
.Empty)
{
return
new
Int64();
}
else
{
return
Int64.Parse(value.ToString());
}
}
}