hello team,
Is it possible with GridViewComboBoxColumn to bind to GridViewComboBoxColumn with 2 different collections via ItemSource binding? Here is the question I posted in the Silverlight forum. http://forums.silverlight.net/p/241794/603526.aspx/1?p=True&t=634561231912631344
Visual below and current code sample of that at bottom.
Thank you very much.
Greg
Is it possible with GridViewComboBoxColumn to bind to GridViewComboBoxColumn with 2 different collections via ItemSource binding? Here is the question I posted in the Silverlight forum. http://forums.silverlight.net/p/241794/603526.aspx/1?p=True&t=634561231912631344
Visual below and current code sample of that at bottom.
Thank you very much.
Greg
using
System.Collections.Generic;
using
System.Linq;
using
System.Windows;
using
System.Windows.Controls;
using
System.ComponentModel;
using
Telerik.Windows.Controls;
namespace
GridCombo
{
public
partial
class
MainPage : UserControl, INotifyPropertyChanged
{
LookupCode[] codes;
List<SampleData> items;
public
MainPage()
{
InitializeComponent();
DataContext =
this
;
items = (from c
in
Enumerable.Range(0, 10)
select
new
SampleData
{
Code =
"code1"
,
Name =
"Some name"
+ c
}).ToList();
codes =
new
LookupCode[4];
codes[0] =
new
LookupCode
{
Code =
"code1"
,
Name =
"A"
};
codes[1] =
new
LookupCode
{
Code =
"code2"
,
Name =
"B"
};
codes[2] =
new
LookupCode
{
Code =
"code3"
,
Name =
"C"
};
codes[3] =
new
LookupCode
{
Code =
"code4"
,
Name =
"D"
};
InvokePropertyChanged(
new
PropertyChangedEventArgs(
"LookupCodes"
));
InvokePropertyChanged(
new
PropertyChangedEventArgs(
"Items"
));
((GridViewComboBoxColumn)
this
.SampleGrid.Columns[0]).ItemsSource =
this
.codes;
}
public
List<SampleData> Items
{
get
{
return
items; }
}
public
IEnumerable<LookupCode> LookupCodes
{
get
{
return
codes; }
}
public
event
PropertyChangedEventHandler PropertyChanged;
public
void
InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if
(handler !=
null
) handler(
this
, e);
}
}
public
class
LookupCode
{
public
string
Code {
get
;
set
; }
public
string
Name {
get
;
set
; }
}
public
class
SampleData : INotifyPropertyChanged
{
private
string
code;
private
string
name;
public
string
Code
{
get
{
return
code;
}
set
{
code = value;
this
.OnPropertyChanged(
"Code"
);
}
}
public
string
Name
{
get
{
return
name;
}
set
{
name = value;
this
.OnPropertyChanged(
"Name"
);
}
}
public
event
PropertyChangedEventHandler PropertyChanged;
protected
virtual
void
OnPropertyChanged(
string
name)
{
if
(
this
.PropertyChanged !=
null
)
{
this
.PropertyChanged(
this
,
new
PropertyChangedEventArgs(name));
}
}
}
}
<
UserControl
xmlns:local
=
"clr-namespace:GridCombo"
xmlns:telerik
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
x:Class
=
"GridCombo.MainPage"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"20"
></
RowDefinition
>
<
RowDefinition
></
RowDefinition
>
</
Grid.RowDefinitions
>
<
telerik:RadGridView
x:Name
=
"SampleGrid"
Grid.Row
=
"1"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding Items}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewComboBoxColumn
DataMemberBinding
=
"{Binding Code, Mode=TwoWay}"
Header
=
"Class"
SelectedValueMemberPath
=
"Code"
DisplayMemberPath
=
"Name"
ItemsSource
=
"{Binding Path=LookupCodes}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
</
UserControl
>