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

Row Not Selected When Using CellTemplate

3 Answers 255 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 15 Nov 2011, 08:39 AM
Sample column:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SelLang}">
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <ComboBox SelectedValue="{Binding Path=SelLang}"
                      ItemsSource="{Binding Langs}" 
                      SelectedValuePath="LanguageCode" 
                      DisplayMemberPath="LanguageName" />
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>

Clicking any other column selects the row (we have the indicator turned on to easily see this), however, clicking and selecting items in this combobox doesn't activate the row. Which property or other trick did I miss?

Thanks,
 Chris

3 Answers, 1 is accepted

Sort by
0
DBlagg
Top achievements
Rank 1
answered on 01 Mar 2013, 02:57 PM
We have the same issue as this unanswered post and are currently on the Q3 2012 version.
There is a RadButton CellTemplate in the first grid column and the desired functionality is to delete the row associated with the button.
However, the selected row is not changing when you click the button in the template so it is deleting the wrong row.
We was using WPF with the MVVM coding pattern.
What is the best way to select the cell/row when the button is clicked?

Thanks,
Dennis
0
Yoan
Telerik team
answered on 01 Mar 2013, 04:08 PM
Hi Dennis,

Please, check this online example for a reference. Although it is for Silverlight, you can find the same in your local copy of WPF demos.

Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
CindyLu
Top achievements
Rank 1
answered on 21 Mar 2013, 04:41 PM
Resolved - answer below
*****
The link to the online example that Yoan posted doesn't seem to address the question, at least as far as I can tell.  The question is how to get SelectedItem to set when clicking on a cell in a row that is defined through a data template in a GridViewColumn.  The example in the link only has columns that are GridViewDataColumns. 

The issue is that if I click on a column that is defined by a template, the set for SelectedItem does not fire.  How do you make it so that the SelectedItem set fires when a user is working on a column that is defined by a template?

*****
Found the answer here - takes a minor bit of code behind, but still works well if you pull in the View Model.  So to hook it up using MVVM, something like this works well:

 

private void TestPassedClick( object sender, RoutedEventArgs e ) { 

  GridViewRow row = ( (CheckBox)sender ).ParentOfType<GridViewRow>();

  if (row == null) return;

 

  row.IsSelected = true;
 
SkateTestsEditViewModel vm = (SkateTestsEditViewModel)DataContext;

 CheckBox cb = e.Source as CheckBox;

  vm.SelectedScoreResult.Passed_ = cb.IsChecked;

}

Tags
GridView
Asked by
Christoph
Top achievements
Rank 1
Answers by
DBlagg
Top achievements
Rank 1
Yoan
Telerik team
CindyLu
Top achievements
Rank 1
Share this question
or