Set property isSelected for cell

3 posts, 0 answers
  1. George
    George avatar
    9 posts
    Member since:
    Mar 2014

    Posted 21 Jul 2014 Link to this post

    I am using Telerik version 2014.1.331.45

    I have a RadGridView like:
    <telerik:RadGridView Name="RadGridView" ItemsSource="{Binding DynamicValues, Mode=TwoWay}" <br>                             SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}" CanUserDeleteRows="True" <br>                             CanUserInsertRows="True" CanUserReorderColumns="False" CanUserSortColumns="False" <br>                             ShowGroupPanel="False"<br>                             IsFilteringAllowed="False"<br>                             SelectionMode="Extended"<br>                             SelectionUnit="Mixed"<br>                             IsSynchronizedWithCurrentItem="True" <br>                             behavoirs:ValidationBehavior.IsValidationEnabled="True" ClipboardPasteMode="SkipHiddenColumns">

    I need to select all cells of column on clicked column header

    i wrote next code for make header clickable:
    foreach (var column in RadGridView.Columns)<br>            {<br>                var temp = column.Header;<br>                column.Header = new MyButton { Content = temp.ToString(), ViewModel = this };<br>            }

    and custom button class:

     private class MyButton :RadButton<br>        {<br>            public override string ToString()<br>            {<br>                return Content.ToString();<br>            }<br><br>            protected override void OnMouseDown(MouseButtonEventArgs e)<br>            {<br>                if (ViewModel.columnHeaders.ContainsKey(e.Source.ToString()))<br>                {<br>                    foreach (var value in ViewModel.RadGridView.Items)<br>                    {<br>                        var row = ViewModel.RadGridView.ItemContainerGenerator.ContainerFromItem(value) as GridViewRow;<br>                        if (row != null) row.Cells[index].IsSelected ???<br>                    }<br>                }<br>                base.OnMouseDown(e);<br>            }<br><br>            public EditViewModelBase ViewModel { get; set; }<br>        }

    but row.Cells[index]  does not have property IsSelected, how I can set cell property selected?

  2. George
    George avatar
    9 posts
    Member since:
    Mar 2014

    Posted 21 Jul 2014 Link to this post

    <telerik:RadGridView Name="RadGridView" ItemsSource="{Binding DynamicValues, Mode=TwoWay}"                      SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}" CanUserDeleteRows="True"                            CanUserInsertRows="True" CanUserReorderColumns="False" CanUserSortColumns="False"
                              ShowGroupPanel="False"
                         IsFilteringAllowed="False"
                                SelectionMode="Extended"
                                SelectionUnit="Mixed"
                               IsSynchronizedWithCurrentItem="True"                             behavoirs:ValidationBehavior.IsValidationEnabled="True" ClipboardPasteMode="SkipHiddenColumns">
    foreach (var column in RadGridView.Columns)          
    {              
      var temp = column.Header;
                 
      column.Header = new MyButton { Content = temp.ToString(), ViewModel = this };      
    }

    private class MyButton :RadButton
    {
       public override string ToString()
       {
           return Content.ToString();
       }
       
       protected override void OnMouseDown(MouseButtonEventArgs e)
       {               
            if (ViewModel.columnHeaders.ContainsKey(e.Source.ToString()))
            {
                foreach (var value in ViewModel.RadGridView.Items)
                {
                  var row =
    ViewModel.RadGridView.ItemContainerGenerator.ContainerFromItem(value) as GridViewRow;
                                        if (row != null) row.Cells[index].IsSelected ???
                }
            }
            base.OnMouseDown(e);
        }
        public EditViewModelBase ViewModel { get; set; }
    }
  3. George
    George avatar
    9 posts
    Member since:
    Mar 2014

    Posted 21 Jul 2014 Link to this post

    I find answer thanks:

    thre is two ways:
    1. need to cast row to GridViewCell
    ((GridViewCell) row.Cells[1]).IsSelected = true;
    2. RadGridView.SelectedCells.Add(item);
Back to Top