Row Not Selected When Using CellTemplate

4 posts, 0 answers
  1. Christoph
    Christoph avatar
    19 posts
    Member since:
    Apr 2008

    Posted 15 Nov 2011 Link to this post

    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
  2. DBlagg
    DBlagg avatar
    4 posts
    Member since:
    Oct 2012

    Posted 01 Mar 2013 Link to this post

    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
  3. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 01 Mar 2013 Link to this post

    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.

  4. CindyLu
    CindyLu avatar
    1 posts
    Member since:
    Jul 2012

    Posted 21 Mar 2013 Link to this post

    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;

    }

Back to Top