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

RadGridView selectedrow is not selected in Silverlight MVVM

2 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Baskar
Top achievements
Rank 1
Baskar asked on 29 Aug 2011, 01:11 PM
Dear Experts

am using Silverlight MVVM pattern. in my View am have placed radGridview control as show below

 <telrik:RadGridView x:Name="EmployeeListGridView" ItemsSource="{Binding}"  SelctedItem={Binding EmployeeDTO, Mode=Twoway} AutoGenerateColumns="True"  Height="Auto" />

and in the code-behind i have set as
 public EmployeeList()
        {
            InitializeComponent();

            EmployeeListViewModel empListViewModel = new EmployeeListListViewModel();
           this.DataContext = empListViewModel.EmployeeDetailList;
         }

ViewModel.cs
   public EmployeeDTO SelectedDTO
        {
            get
            {
                return _selectedDTO;
            }

            set
            {
                _selectedDTO = value;
                OnPropertyChanged("SelectedDTO");
            }
        }

        public ObservableCollection<EmployeeDTO> EmployeeDetailList
        {
            get
            {
                return _employeeDetailList;
            }

            set
            {
                _employeeDetailList= value;
                OnPropertyChanged("EmployeeDetailList");
            }
        }

When i select any one of record and click on the Edit Button, i got null in the SelectedDTO as shown below.

private void Edit_click(object sender, EventArgs args)
{
            if (SelectedDTO != null)
            {
              MessageBox.Show(SelectedDTO);
            }
}

Please solve my issue and correct my code if i done any wrong.

Thanks in Advance.

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Aug 2011, 01:40 PM
Hi Baskar,

You need to bind the SelectedItem to the property defined in your ViewModel -  SelectedDTO, not to EmployeeDTO.

All the best,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Baskar
Top achievements
Rank 1
answered on 30 Aug 2011, 07:04 AM
Hi Thanks for your reply

As you said, i have changed to SelctedItem={Binding SelectedDTO}, but still am getting a null value in the following if statement

           if (SelectedDTO != null)
            {
              MessageBox.Show(SelectedDTO);
            }

Please tell me the correct solution, how to get the selectedDTO from Telerikdatagrid.

Tags
GridView
Asked by
Baskar
Top achievements
Rank 1
Answers by
Maya
Telerik team
Baskar
Top achievements
Rank 1
Share this question
or