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

Row indicator with selectionmode=cell

2 Answers 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gopala
Top achievements
Rank 1
Gopala asked on 26 Jun 2012, 03:43 PM
Hi,

We are using Q2 2010 telerik controls. We want to use Row indicator with SelectionUnit = Cell for RadGridView.

When user clicks on Row Indicator column the entire row must be selected but when user clicks a cell inside RadGridView only that cell must be selected but for me it is selecting entire row.

I also noticed that for row indicator functionality, I must give SelectionUnit = FullRow , but we want SelectionUnit =Cell.

Please see below code for what I am doing

<telerik:RadGridView     x:Name="gridCusip"
                         ItemsSource="{Binding Nodes}"
                         RowIndicatorVisibility="Visible"
                         IsSynchronizedWithCurrentItem="True"
                         IsReadOnly="True"
                         CanUserReorderColumns="False"
                         CanUserFreezeColumns="False"
                         EnableColumnVirtualization="False"
                         EnableRowVirtualization="True"
                         ScrollMode="RealTime"
                         ClipboardCopyMode="Default"
                         SelectionMode="Extended"
                         SelectionUnit="Cell"
                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         ShowGroupFooters="False"
                         ShowGroupPanel="False">

I also tried below code

this.gridCusip.CurrentCellChanged += new EventHandler<GridViewCurrentCellChangedEventArgs>(gridCusip_CurrentCellChanged);

 void gridCusip_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
    {
      this.gridCusip.CurrentItem = e.NewCell.DataContext;
    }

Please advice me how to solve this.

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Gopala
Top achievements
Rank 1
answered on 29 Jun 2012, 10:09 PM
I donot understand why but I never get any help or responses to my queries here.

I fixed this issue as below

In constructor
this.AddHandler(RadGridView.MouseLeftButtonDownEvent, new MouseButtonEventHandler(gridCusip_MouseLeftButtonDown), true);

void gridCusip_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      if (this.gridCusip.SelectionUnit != GridViewSelectionUnit.Cell)
      {
        var element = e.OriginalSource as FrameworkElement;
        var cell = element.ParentOfType<GridViewCell>();
 
        if (cell != null)
        {
          this.gridCusip.SelectionUnit = GridViewSelectionUnit.Cell;
          var cellInfo = new GridViewCellInfo(cell);
          //this.gridCusip.SetSelectionAnchor(cellInfo);
          this.gridCusip.SelectedCells.Add(cellInfo);
        }
      }
    }


 private void gridCusip_RowLoaded(object sender, RowLoadedEventArgs e)
    {
      GridViewRow row = e.Row as GridViewRow;
      if (row != null)
      {
        Border indicatorPresenter = row.ChildrenOfType<Border>().Where(b => b.Name == "PART_IndicatorPresenter").FirstOrDefault();
        indicatorPresenter.MouseLeftButtonDown += new MouseButtonEventHandler(indicatorPresenter_MouseLeftButtonDown);
      }	
    }
 
    private void indicatorPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      if (this.gridCusip.SelectionUnit != GridViewSelectionUnit.FullRow)
      {
        var border = sender as Border;
        var row = border.ParentOfType<GridViewRow>();
 
        this.gridCusip.SelectionUnit = GridViewSelectionUnit.FullRow;
 
        this.gridCusip.SelectedItem = row.Item;
        //this.gridCusip.SetSelectionAnchor(row.Item);
      }
    }
0
Dimitrina
Telerik team
answered on 15 Feb 2013, 02:00 PM
Hello,

I am writing with an update that we have introduced such feature out-of-the-box with our official Q3 2012 SP1 release. All you need to do is set SelectionUnit property of the grid to be "Mixed".  

I hope this helps.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Gopala
Top achievements
Rank 1
Answers by
Gopala
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or