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

Set property isSelected for cell

2 Answers 181 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 21 Jul 2014, 02:12 PM
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 Answers, 1 is accepted

Sort by
0
George
Top achievements
Rank 1
answered on 21 Jul 2014, 02:17 PM
<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; }
}
0
George
Top achievements
Rank 1
answered on 21 Jul 2014, 02:30 PM
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);
Tags
GridView
Asked by
George
Top achievements
Rank 1
Answers by
George
Top achievements
Rank 1
Share this question
or