Hi,
I am facing small problem.That I want know selectedItems in radgridview.I am using MVVM pattern.In code behind file i am able to get the selectedItems.But in my viewmodel I am I am not getting.I had tried with following code samples.
Thanks and Regards
Naresh Mesineni
I am facing small problem.That I want know selectedItems in radgridview.I am using MVVM pattern.In code behind file i am able to get the selectedItems.But in my viewmodel I am I am not getting.I had tried with following code samples.
<Style TargetType="{x:Type telerik:GridViewRow}">and
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
<telerik:RadGridView.ItemContainerStyle>Please help me in this issue.
<Style TargetType="{x:Type telerik:GridViewRow}">
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
</telerik:RadGridView.ItemContainerStyle> SelectedYN is a property in my viewModel.(Its updates the ItemsSource)
Thanks and Regards
Naresh Mesineni
6 Answers, 1 is accepted
0
Hi Naresh,
You have pasted just the XAMl, not the ViewModel nor the way you read the state in code behind.
So having the XAML only I guess the first place to check would be the Binding mode . I have noticed it is OneWayToSource.
All the best,
Pavel Pavlov
the Telerik team
You have pasted just the XAMl, not the ViewModel nor the way you read the state in code behind.
So having the XAML only I guess the first place to check would be the Binding mode . I have noticed it is OneWayToSource.
All the best,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
naresh
Top achievements
Rank 1
answered on 02 Nov 2011, 09:07 AM
Hi Pavlov,
Thanks for reply.Here I am pasting my viewmodel and code part.As I mentioned I am using MVVM pattern.
Thanks for reply.Here I am pasting my viewmodel and code part.As I mentioned I am using MVVM pattern.
private string projectNumber;
public string ProjectNumber
{
get { return projectNumber; }
set
{
if (value != projectNumber)
{
projectNumber = value;
NotifyOfPropertyChange(() => ProjectNumber);
}
}
}private string selectedYN;
public string SelectedYN
{
get { return selectedYN; }
set
{
if (value != selectedYN)
{
selectedYN= value;
NotifyOfPropertyChange(() => SelectedYN);
}
}
}
Here I am accessing SelectedItems like thisvar selectedItems = DataSourceItems.Where(x => x.SelectedYN).ToList();DataSourceItems was gridview datasource.in XAML I have tried following ways.Tried with all types of modes.<Style TargetType="{x:Type telerik:GridViewRow}">and
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
<telerik:RadGridView.ItemContainerStyle>
<Style TargetType="{x:Type telerik:GridViewRow}">
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
</telerik:RadGridView.ItemContainerStyle> Please help in this matter.If possible provide example. Thanks and Regards Naresh Mesineni
0
Dave
Top achievements
Rank 1
answered on 31 Jul 2014, 12:14 PM
Pavlov, or someone from Telerik
I am having this exact same problem. Is there a solution?
Dave
I am having this exact same problem. Is there a solution?
Dave
0
Dave
Top achievements
Rank 1
answered on 31 Jul 2014, 01:23 PM
In case this is of any help to anyone, I solved the problem. In my case it was caused by the fact that all our telerik styles are overridden by a complete set of styles that implement our company look-and-feel. So we don't use the telerik XAML, we use a set of BAML DLLs developed by our UX team.
Anyway, try this:
<Style x:Key="MyGridViewRowStyle" TargetType="{x:Type telerik:GridViewRow}" BasedOn="{StaticResource {x:Type telerik:GridViewRow}}">
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
<Style TargetType="{x:Type telerik:GridViewRow}" BasedOn="{StaticResource MyGridViewRowStyle}" />
I don't know if this is a workaround for a bug in WPF, or whether it is necessary for some good reason that I don't understand, but it worked for me.
Anyway, try this:
<Style x:Key="MyGridViewRowStyle" TargetType="{x:Type telerik:GridViewRow}" BasedOn="{StaticResource {x:Type telerik:GridViewRow}}">
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectedYN}"/>
</Style>
<Style TargetType="{x:Type telerik:GridViewRow}" BasedOn="{StaticResource MyGridViewRowStyle}" />
I don't know if this is a workaround for a bug in WPF, or whether it is necessary for some good reason that I don't understand, but it worked for me.
0
Dave
Top achievements
Rank 1
answered on 31 Jul 2014, 01:28 PM
PS. On second thoughts I don't think the company style overrides have anything to do with it. It's just an oddity of WPF.
0
Hi,
You can check this github example on how to bind the SelectedItems to a collection from your view model.
Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our brand new SDK Samples Browser. You can also use it to review the examples.
I hope it will work better for you. Let me know what your observations are.
Regards,
Didie
Telerik
You can check this github example on how to bind the SelectedItems to a collection from your view model.
Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our brand new SDK Samples Browser. You can also use it to review the examples.
I hope it will work better for you. Let me know what your observations are.
Regards,
Didie
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.