This is a migrated thread and some comments may be shown as answers.

[Solved] Binding and SelectedItem

6 Answers 337 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mily
Top achievements
Rank 1
Mily asked on 07 Aug 2009, 11:26 AM

Hi there,

 

I must say I am generally impressed with quality of the RAD controls. However I think I found a bug in the RadGridView control – Binding to SelectedItem does not have any effect:

 

<UserControl

    x:Class="SilverlightApplication1.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    xmlns:local="clr-namespace:SilverlightApplication1"

    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <UserControl.DataContext>

        <local:TestViewModel />

    </UserControl.DataContext>

    <Grid x:Name="LayoutRoot" >

        <telerikGrid:RadGridView AutoGenerateColumns="True"

                                 ItemsSource="{Binding List}"

                                 SelectedItem="{Binding SelectedItem, Mode=TwoWay}">

        </telerikGrid:RadGridView>

        <!— MS grid works fine -->

        <!--<data:DataGrid AutoGenerateColumns="True"

                       ItemsSource="{Binding List}"

                       SelectedItem="{Binding SelectedItem, Mode=TwoWay}">

        </data:DataGrid>-->

    </Grid>

</UserControl>

 

ViewModel:

 

public class TestViewModel : INotifyPropertyChanged

     {

           public TestViewModel()

           {

                var list = from i in Enumerable.Range(1, 10)

                              select i.ToString();

 

                List = list.ToList();

                SelectedItem = List[0];

           }

           /// <summary>

           ///

           /// </summary>

           public event PropertyChangedEventHandler PropertyChanged;

 

           /// <summary>

           ///

           /// </summary>

           /// <param name="property"></param>

           protected void OnPropertyChanged(string property)

           {

                if (PropertyChanged != null)

                     PropertyChanged(this, new PropertyChangedEventArgs(property));

           }

 

           private IList<string> list;

           /// <summary>

           ///

           /// </summary>

           public IList<string> List

           {

                get

                {

                     return list;

                }

                private set

                {

                     this.list = value;

                     this.OnPropertyChanged("List");

                }

           }

 

           private string selectedItem;

           /// <summary>

           ///

           /// </summary>

           public string SelectedItem

           {

                get

                {

                     return this.selectedItem;

                }

                set

                {

                     // this will not get invoked when used with telerik RadGridView

                     this.selectedItem = value;

                     this.OnPropertyChanged("SelectedItem");

                }

           }

     }

 

Using the same code with MS data grid works fine. I have tried different versions of Telerik controls with no luck:

·          2009.2.701.1020

·          2009.2.720.1020

·          2009.2.724.1020 (latest dev build)

 

I know I can solve the problem by using code behind but I would prefer to bind view to underlying view model. I saw few people reporting the same bug in other WPF/Silverlight Telerik controls.


Kind Regards,

Milosz

 

 


6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 12 Aug 2009, 08:05 AM
Hello Milosz Skalecki,

Unfortunately, we have identified a bug and will start working on it immediately. I hope that we will be able to resolve is as soon as possible.

We would like to apologize for the inconvenience.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Neal Sanche
Top achievements
Rank 1
answered on 23 Nov 2009, 09:17 PM

I am using the Q3 2009 release and this problem still exists. The initial selection of the appropriate item in the DataGrid does not follow the data binding that is set for the SelectedItem property. Selecting another row in the DataGrid is working though, so the bound property gets updated when the selection changes. It's just the initial selection that seems broken.

Let me know when this gets fixed.

-Neal
0
Miguel Rios
Top achievements
Rank 1
answered on 29 Jan 2010, 11:16 PM
Hi to the Telerik team,

i was wondering if this issue was resolved in the new release?

I need to set the selected item when i reload the source item of the grid, but nothing happens... any item is selected despite i send the properties of the objects to select...


Could you help with this? or the new release fixed it?

By the way, I am using a two way binding to the selected item, I reload the data in the grid and can't select a specific item in a row...

Thanks and
Greeting!
0
Rossen Hristov
Telerik team
answered on 03 Feb 2010, 01:07 PM
Hello Miguel Rios,

It is working. Please check the attached sample.

Greetings,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Miguel Rios
Top achievements
Rank 1
answered on 05 Feb 2010, 04:41 AM
Hi Ross,

the problem with this is that when i reload the itemSource of the grid, and give a value to the selectedItem, it doesn't appear as selected in the grid, how can i acchieve that?

As an example, before i reload the itemSource of the grid, i save the selectedItem at that moment, so when i reload it, that object appears as selected, but that doesn't occur.

Any idea of what is hapenning?

Greetings.
0
Rossen Hristov
Telerik team
answered on 08 Feb 2010, 12:37 PM
Hello Miguel Rios,

Are sure that the item that you have saved exists in the new data source? If the new data source that you assign does not contain the original item that you have saved then nothing will be selected and that is normal.

In case this is not so -- could you please send me your sample project and I will debug it to see what is going on.

Sincerely yours,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Mily
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Neal Sanche
Top achievements
Rank 1
Miguel Rios
Top achievements
Rank 1
Share this question
or