Losing multi-select when right click for context menu

8 posts, 0 answers
  1. Chris Breymeyer
    Chris Breymeyer avatar
    5 posts
    Member since:
    Nov 2007

    Posted 10 Jan 2008 Link to this post

    Hi,

    I am using the Rad gridview for windows forms.  I have multiselect enabled and it mostly works like a charm (holding shift down and clicking with the mouse still does not select multiple rows).

    However, when I use some other method to select multiple rows (holding the control key down for example) and I right click to bring up my context menu, all of the rows I had selected become unselected except for the actual row I right-clicked on.

    Is this a known issue?  Is there a workaround for this problem?

    Thanks,

    John Reynolds
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 11 Jan 2008 Link to this post

    Hi John Reynolds,

    Thank you for reporting this issue.

    We managed to reproduce  it locally. We apologize for the caused inconvenience. We will address this issue in our upcoming release. Don't hesitate to contact us if you have other questions.

    Kind regards,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. kumar
    kumar avatar
    6 posts
    Member since:
    Jul 2008

    Posted 09 Jul 2008 Link to this post

    Is there any way in Q1 2008 release to get all selected rows ( multiselect), after right clicking on a row and opening context menu. I need to process all the rows depending on the context menu chosen. Currently after right click only one row remains selected (the one on which right-click was done).

    Other queries:
    1. Is there a way to have different column types in same column in different rows e.g. I dont want to show button in a column if the text in that is empty.
    2. Is there a way to have linkColumn.
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 11 Jul 2008 Link to this post

    Hi kumar,

    Thank you for your questions.

    Yes, there is a way to keep the selected rows selected after raising the context menu (FYI, we plan to address this usability issue in one of our upcoming releases). You can work around this by using a descendant class of RadGridView. Consider the following code snippet below:

    public class MyGrid : RadGridView 
        List<GridViewRowInfo> savedSelectedRows = new List<GridViewRowInfo>(); 
     
        public override string ThemeClassName 
        { 
            get { return typeof(RadGridView).FullName; } 
            set { } 
        } 
     
        public List<GridViewRowInfo> SavedSelectedRows 
        { 
            get { return this.savedSelectedRows; } 
        } 
     
        protected override void OnMouseDown(MouseEventArgs e) 
        { 
            if (e.Button == MouseButtons.Right) 
            { 
                savedSelectedRows.Clear(); 
                foreach (GridViewRowInfo row in this.SelectedRows) 
                { 
                    savedSelectedRows.Add(row); 
                } 
            } 
     
            base.OnMouseDown(e); 
        } 

    Regarding your queries:

    1. Use the following code snippet to show buttons only when there is data in the corresponding cell:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
        GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn; 
        if (column != null && column.FieldName == "Date"
        { 
            GridDataCellElement cell = (GridDataCellElement)e.CellElement; 
     
            if (cell.Children.Count == 0) 
            { 
                RadButtonElement button = new RadButtonElement(); 
                cell.Children.Add(button); 
                ApplyThemeToElement(button, "ControlDefault");  
            } 
     
            if (cell.Value == DBNull.Value || string.IsNullOrEmpty((string)cell.Value)) 
            { 
                cell.Children[0].Visibility = ElementVisibility.Hidden; 
            } 
            else 
            { 
                cell.Children[0].Visibility = ElementVisibility.Visible; 
                ((RadButtonElement)cell.Children[0]).Text = cell.Value.ToString(); 
            } 
            cell.Text = ""
        } 
     
    private void ApplyThemeToElement(RadItem item, string themeName) 
        DefaultStyleBuilder builder = ThemeResolutionService.GetStyleSheetBuilder((RadControl)item.ElementTree.Control, item.GetThemeEffectiveType().FullName, string.Empty, themeName) 
                                      as DefaultStyleBuilder; 
     
        if (builder != null
            item.Style = new XmlStyleSheet(builder.Style).GetStyleSheet(); //clone because control might modify it later  
     

    2. Currently RadGridView doesn't have a specialized hyperlink column, but it can be implemented by processing the CellFormatting event. Take a look at this forum post.

    Please let me know if you need further assistance.
     

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 28 Feb 2012 Link to this post

    I've got 2012 Q1 and still having this problem ... namely,

    • right click will always change cell to mouse pointer
    • the context menu only shows on every other right-click

    The suggested work around didn't work because I am not subclassing the grid control.  However, the following did work for me with regards to getting my context menu to always show up: 
      Private Sub gridView_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgsHandles gridView.MouseDown
     
                If e.Button = Windows.Forms.MouseButtons.Right Then
                    m_contextMenu.Show(Me, e.Location)
                Else
                    MyBase.OnMouseDown(e)
                End If
     
            End Sub

    It still does change the cell location and also the selected row (if you move off the desired row)... but at least now the user can get at the context menu much easier. However, is there a work around to the right click changing the selection yet as it's now 2012 :)

  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 02 Mar 2012 Link to this post

    Hello Eric,

    If I understand your question correctly, you want to display a context menu without changing the current cell location. The default RadGridView menu is context specific to the current cell and it can work correctly only when the clicked cell is current. However, you can change this behavior by using a custom context menu and overriding the OnMouseDown method in BaseGridBehavior. Consider the following sample:
    this.radGridView1.GridBehavior = new CustomGridBehavior();
     
    public class CustomGridBehavior : BaseGridBehavior
    {
        public override bool OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                RadDropDownMenu menu = new RadDropDownMenu();
                menu.Items.Add(new RadMenuItem("Item 1"));
                menu.Items.Add(new RadMenuItem("Item 2"));
                menu.Items.Add(new RadMenuItem("Item 3"));
                menu.Show(GridControl.PointToScreen(e.Location));
                return true;
            }
            return base.OnMouseDown(e);
        }
    }

    I hope this helps.
     
    Kind regards,
    Jack
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  7. Aamir
    Aamir avatar
    1 posts
    Member since:
    Jul 2013

    Posted 29 Jul 2013 Link to this post

    I have latest telerik WPF controls and I can still see same problem. Is issue mentioned in initial post is fixed ? 
  8. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 31 Jul 2013 Link to this post

    Hi Aamir,

    Please note that the current forum thread concerns RadGridView for WinForms. As it seems that you are using RadControls for WPF (and RadGridView for WPF in particular), I would kindly ask you to address your WPF-related question in the appropriate WPF section. This will allow our community members interested in RadGridView for WPF to find your topic more easily.

    Thank you for your understanding.

    Regards,
    Nikolay
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top