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

SelectedItem and Binding (MVVM)

3 Answers 197 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Srdjan
Top achievements
Rank 1
Srdjan asked on 10 Jul 2012, 10:13 AM

Hi,

I have a problem with GridView (2012.1.326.40):
<telerik:RadGridView CanUserSortColumns="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Name="ProductionQuantityTable" IsSynchronizedWithCurrentItem="True"

grid:RadGridViewHelper.ColumnsCollection="{Binding Path=ColumnsCollection, NotifyOnSourceUpdated=True}" SelectedItem="{Binding SelectedQuantity, Mode=TwoWay}" SelectionMode="Single" ItemsSource="{Binding Quantities}" />

 
ViewModel:

 

  private ProductionQuantityItemViewModel _selectedQuantity;
  public ProductionQuantityItemViewModel SelectedQuantity
  {
   get
   {
    if (_selectedQuantity == null && _project.CurrentQuantityVariantId.HasValue)
    {
     _selectedQuantity = _quantities.FirstOrDefault(q => q.QuantityVariant.Identity == _project.CurrentQuantityVariantId.Value);
    }
    return _selectedQuantity;
   }
   set
   {
    _selectedQuantity = value;
    _project.CurrentQuantityVariantId = _selectedQuantity.QuantityVariant.Identity;
    RaisePropertyChanged(() => SelectedQuantity);
    _eventAggregator.GetEvent<ProductionQuantityChangedEvent>().Publish(_selectedQuantity.QuantityVariant.ProductionQuantity);
   }
  }

 

 

SelectedItem is binding to ViewModel, but when I set SelectedQuantity in ViewModel I don't get any graphical representation in UI.

What I'm trying to achieve is that when I load table that row is selected (based on data in DB). In this example row #2.
http://gyazo.com/38e88488d872989beb03b447a6e545d6

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 Jul 2012, 01:39 PM
Hello,

 I have tested setting the SelectedItem for the GridView through the corresponding property in the ViewModel and the item was marked selected as expected.

Is the item that you select currently in view? May I ask you how is the "Quantities" collection defined?

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Srdjan
Top achievements
Rank 1
answered on 10 Jul 2012, 01:46 PM
Quantities (child view model) is filled in constructor:

        public ObservableCollection<ProductionQuantityItemViewModel> Quantities
        {
            get { return _quantities; }
        }

One more thing when I set IsSynchronizedWithCurrentItem to true than I see first row selected, and when it is false than no line is selected. Also setting CurrentItem in code behind doesn't do anything in my view.

Just checked in code behind, SelectedItem is null although I set it in ViewModel, and of course when row is clicked in UI then it is set.
0
Dimitrina
Telerik team
answered on 10 Jul 2012, 02:28 PM
Hi,

Thank you for this additional information.

So far I am not able to reproduce such an issue with the selection. May I ask you whether you have tested with the latest binaries? If the problem still remains, would it be possible for you to isolate the issue in a sample project which we could debug locally?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Srdjan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Srdjan
Top achievements
Rank 1
Share this question
or