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

[Solved] SelectedItem binding

3 Answers 190 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.
Vidar
Top achievements
Rank 1
Vidar asked on 26 Mar 2009, 12:24 PM
Hi.

I am unable to bind to the SelectedItem attribute in RadGridView. It ends with errors on page.
The code below works with an ordinary ListBox control.

I am using VMMV models to avoid too much code in the code-behind files. Everything is bound together using the ninject.
I do not want to use the selecttion changed event.

Are you able to see the problem?

DataContext

 

="{Binding Path=AttributeViewModel, Source={StaticResource serviceLocator}}"

 


 

 

<telerikGridView:RadGridView 
    IsReadOnly="True" ColumnsWidthMode="Auto" AutoGenerateColumns="False"

 

 

    ItemsSource="{Binding Path=AttributeTypes, Mode=OneWay}"
    SelectedItem="{Binding Path=SelectedAttributeType, Mode=TwoWay}">

 

 

 

<telerikGridView:RadGridView.Columns>

 

 

<

 

TextBlock Text="{Binding SelectedAttributeType.Name}" />

 

 

 

 

public AttributeType SelectedAttributeType

 

{

 

    get { return selectedAttributeType; }

 

 

    set

 

 

 

 

    {

 

        if (selectedAttributeType != value && value != null)

 

        {

            selectedAttributeType =

value;

 

            RaisePropertyChanged(

"SelectedAttributeType");

 

        }

    }

}


Regards
Vidar Steen

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 30 Mar 2009, 02:04 PM
Hi Vidar,

I cannot reproduce the issue you described.

I'm attaching a sample application which is the result of my attempts to simulate the problem. You can use this example to provide me with more detailed information about your scenario.

Sincerely yours,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Vidar
Top achievements
Rank 1
answered on 31 Mar 2009, 11:11 AM

Hi.

Thank you for your answer.


I have found that setting the SelectedPerson in your example reproduces the error I am talking about. I changed the Persons list in your example to ObservableCollection. If you do the changes below to your code you will get the error in question.

public PersonViewModel()

{

    this.Persons = this.CreatePersonList();

    SelectedPerson = Persons[0];

}

private ObservableCollection<Person> CreatePersonList()

{

    ObservableCollection<Person> persons = new ObservableCollection<Person>();

    for (int i = 0; i < 5; i++)

    {
        
persons.Add(new Person{Age = i, FirstName = "John " + i, LastName = "Doe " + i});

    }

    return persons;

}

 

 

Regards,

Vidar Steen

0
Nedyalko Nikolov
Telerik team
answered on 31 Mar 2009, 01:15 PM
Hi Vidar,

Thank you for the valuable feedback. It seems that this is a bug in our control, so I've updated your Telerik points.

As a workaround you can set "SelectedPerson" after complete loading of the RadGridView. For your reference I'm attaching a modified version of the example you already have.

Greetings,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Vidar
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Vidar
Top achievements
Rank 1
Share this question
or