Hi,
I am having a RadGridView with one particular GridViewDataColumn having a Button and textblock as a cell template. On Click of any of this button, I want to edit the details of that particular row. The RadGridView is bound to an ObservableCollection. On click of the button, I am calling a DelegateCommand to do the action. I am passing the current row as the CommandParameter of that button. In the ViewModel, I am updating the Entity associated with the GridRow. But after I update, the changes are not reflected in the RadGridView. But if i click on that particular cell which is modified, the value gets updated.
I even tried using PagedCollectionView instead of ObservableCollection and tried using PagedCollectionView.Refresh() and PagedCollectionView.CommitEdit() methods to trigger the change but with no success.
How do i fix this problem. I am using Prism & MVVM pattern for development. Below is my code
Note: I have set the DataContext of my View to the ViewModel in View.Xaml.cs
XAML
View Model Class
Model
Any help is appreciated
Thanks
Syam
I am having a RadGridView with one particular GridViewDataColumn having a Button and textblock as a cell template. On Click of any of this button, I want to edit the details of that particular row. The RadGridView is bound to an ObservableCollection. On click of the button, I am calling a DelegateCommand to do the action. I am passing the current row as the CommandParameter of that button. In the ViewModel, I am updating the Entity associated with the GridRow. But after I update, the changes are not reflected in the RadGridView. But if i click on that particular cell which is modified, the value gets updated.
I even tried using PagedCollectionView instead of ObservableCollection and tried using PagedCollectionView.Refresh() and PagedCollectionView.CommitEdit() methods to trigger the change but with no success.
How do i fix this problem. I am using Prism & MVVM pattern for development. Below is my code
Note: I have set the DataContext of my View to the ViewModel in View.Xaml.cs
XAML
<
UserControl.Resources
>
<
local:MainViewModel
x:Key
=
"ViewModel"
></
local:MainViewModel
>
</
UserControl.Resources
>
<
telerik:RadGridView
x:Name
=
"grdView"
AutoGenerateColumns
=
"False"
Height
=
"400"
Width
=
"600"
ItemsSource
=
"{Binding Path=PeopleList, Mode=TwoWay}"
ShowGroupPanel
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=FirstName, Mode=TwoWay}"
UniqueName
=
"First Name"
Width
=
"100"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=LastName, Mode=TwoWay}"
UniqueName
=
"Last Name"
Width
=
"100"
/>
<
telerik:GridViewDataColumn
IsReadOnly
=
"True"
Header
=
"Pick Up Job"
UniqueName
=
"Pick Up Job"
Width
=
"120"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
Width
=
"120"
>
<
TextBlock
x:Name
=
"txtCode"
Text
=
"{Binding Path=PickUpJob, Mode=TwoWay}"
Width
=
"90"
></
TextBlock
>
<
telerik:RadButton
x:Name
=
"btnEllp"
HorizontalAlignment
=
"Right"
Content
=
"..."
Command
=
"{Binding Path=ComponentCommand, Source={StaticResource ViewModel} }"
CommandParameter
=
"{Binding}"
Width
=
"30"
>
</
telerik:RadButton
>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
View Model Class
private
People people;
public
People People
{
get
{
return
people; }
set
{
people = value;
this
.RaisePropertyChanged(() =>
this
.People);
}
}
private
ObservableCollection<People> peopleList =
new
ObservableCollection<People>();
public
ObservableCollection<People> PeopleList
{
get
{
return
peopleList; }
set
{
peopleList = value;
this
.RaisePropertyChanged(() =>
this
.PeopleList);
}
}
private
ICommand componentCommand;
public
ICommand ComponentCommand
{
get
{
if
(componentCommand ==
null
)
{
componentCommand =
new
DelegateCommand<People>(OnComponentCommand);
}
return
componentCommand;
}
set
{ componentCommand = value; }
}
public
MainViewModel()
{
LoadValues();
}
private
void
OnComponentCommand(People pe)
{
pe.LastName =
"New"
;
this.RaisePropertyChanged(() => this.People);
}
private
void
LoadValues()
{
foreach
(var x
in
new
People[] {
new
People { PeopleID=0, CountryID = 0, FirstName =
"Sebastain"
, LastName =
"Vettel"
, PickUpJob =
"P1"
},
new
People { PeopleID=1, CountryID = 1, FirstName =
"Fernando"
, LastName =
"Alonso"
, PickUpJob =
"P2"
},
new
People { PeopleID=2, CountryID = 2, FirstName =
"James"
, LastName =
"Button"
, PickUpJob =
"P1"
},
new
People { PeopleID=3, CountryID = 0, FirstName =
"Michael"
, LastName =
"Schumacher"
, PickUpJob =
"P3"
},
new
People { PeopleID=4, CountryID = 1, FirstName =
"Felipe"
, LastName =
"Masa"
, PickUpJob =
"P4"
},
new
People { PeopleID=5, CountryID = 2, FirstName =
"David"
, LastName =
"Hill"
, PickUpJob =
"P1"
},
new
People { PeopleID=6, CountryID = 2, FirstName =
"Mark"
, LastName =
"Strong"
, PickUpJob =
"P2"
}
})
{
PeopleList.Add(x);
}
}
Model
public
class
People
{
public
int
CountryID {
get
;
set
; }
public
int
PeopleID {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
string
PickUpJob {
get
;
set
; }
}
Any help is appreciated
Thanks
Syam