Cell focus/highlight

16 posts, 2 answers
  1. Svein Thomas
    Svein Thomas avatar
    47 posts
    Member since:
    Nov 2010

    Posted 18 Feb 2011 Link to this post

    Hi,

    My grid is a readonly grid and with FullRow Selection mode. But still are the cells highlighted when i'm clicking in the grid. Look at the attached screenshot.

    How can I disable this highlighting ? 

    I have tried with this code, but still the cell is "in a way" highlighted..

    if (e.CellElement.IsCurrent)
                {
                    e.CellElement.DrawFill = false;
                    e.CellElement.DrawBorder = false;
                }
                else
                {
                    e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
                    e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
                }

    BTW: The EnableHotTracking is truned of.

    Regards
    Svein Thomas
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Feb 2011 Link to this post

    Hello,

    If you are calling this code from the CellFormatting event, then the result should be as per the attached screenshot. Even though it doesn't draw the border, you can still see that it is the current cell (slightly) as there are some other properties that are different (BorderBoxStyle, Shadows etc).

    From the look of it, your event is not being called. Ensure you have set up the event handler as shown
    this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);
    private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.CellElement.IsCurrent)
        {
            e.CellElement.DrawFill = false;
            e.CellElement.DrawBorder = false;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }

    hope that helps
    Richard
  3. Svein Thomas
    Svein Thomas avatar
    47 posts
    Member since:
    Nov 2010

    Posted 18 Feb 2011 Link to this post

    Hi Richard,

    The picture is not with the event attached, that is correct.
    But even when i do attach this event, i still can see a difference in the cell content when clicking the cell. The texts in the cell moves a bit... please try it and you see what i mean...

    Svein Thomas
  4. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Feb 2011 Link to this post

    Hello,

    As mentioned in my previous post, if you want it to truly look alike, then there are a few more properties to set. It looks as though you are using the Default theme, so I can give you the settings for those, though it could also be done of course by definin gyour own theme using the Visual stle Builder.

    The non selected cells, still have a border, but are defined as this..
    private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.CellElement.IsCurrent)
        {
            e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
            e.CellElement.BorderTopColor = Color.FromArgb(255, 190, 106);
            e.CellElement.BorderTopShadowColor = Color.FromArgb(255, 245, 162);
            e.CellElement.BorderBottomColor = Color.FromArgb(255, 190, 106);
            e.CellElement.BorderBottomShadowColor = Color.FromArgb(255, 245, 162);
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BorderTopShadowColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        }

    Hope that helps but let me know if you have further questions
    Richard
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 21 Feb 2011 Link to this post

    Hello,

    Did this help? If so, please remember to mark as answer. If you need further help, just let me know.
    Thanks
    Richard
  6. Svein Thomas
    Svein Thomas avatar
    47 posts
    Member since:
    Nov 2010

    Posted 21 Feb 2011 Link to this post

    Why do we need to write this much code just to turn of the cell focus. This should be in the properties of the grid. Some different cellfocusing options. But yes, it worked :) Thanks for your help!

    Regards
    Svein Thomas
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 21 Feb 2011 Link to this post

    Hi,

    Glad that helped. The cell borders are still there on the other cells, but they are just styled differently under the default theme. In this case we are just changing the style of the border to equal the other cells. You can of course though define your own theme so all cells on a selected row would remain the same.
    Let me know if you have any other questions
    Richard
  8. Svein Thomas
    Svein Thomas avatar
    47 posts
    Member since:
    Nov 2010

    Posted 21 Feb 2011 Link to this post

    Hi again,

    I would be happy if you would guide me on how to change the theme to do this. I already have a customized theme, and i tried to figure out where to set this settings with no luck.

    Regards
    Svein Thomas
  9. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 21 Feb 2011 Link to this post

    Hello,

    To be very honest, VSB is an area that is weaker in my knowledge. I must get to know it better. 

    I have attaached a screenshot of the area that I beleive that you would have to change and the properties that you would need to change are the ones that are detailed in my previous reply.

    I hope this helps, but if you think I might be able to assist you further, do just let me know.
    Richard

    edit// attaching image
  10. Svett
    Admin
    Svett avatar
    728 posts

    Posted 24 Feb 2011 Link to this post

    Hi Svein,

    I suggest that you go through the ControlDefault theme and see how the cell styles are applied in all states. Then you should be able to delete these states (or unassociate respective repositories) in your theme. You can read the online documentation regarding the process of opening a predefined theme. In addition, you can read how to use Visual Style Builder here.

    Kind regards,
    Svett
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  11. Answer
    David
    David avatar
    9 posts
    Member since:
    Sep 2010

    Posted 22 Mar 2011 Link to this post

    I was trying to do the exact same thing today, and I got it to work like this.  It worked wonderfully and without having to set explicit colors, etc. 

    void LiquidRadGridView_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement != null)
        {
            if (e.CellElement.IsCurrent)
            {
                e.CellElement.IsCurrent = false;
                e.CellElement.IsCurrentColumn = false;
            } else
            {
                e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            }
        }
    }
  12. Abdul
    Abdul avatar
    27 posts
    Member since:
    Jan 2017

    Posted 02 Jun 2017 Link to this post

    Hi,

    I have an issue that when a form(I have attached the screenshot) is loaded from another form and focus goes to a particular cell in RadGridView it does not selected(Highlighted with blue color).So that when i want to change the text,i simply do double left mouse click on the cell.Here i want to avoid mouse click,and do it programmatically select the text on the cell.Here is the code snippet:

    private void frmProductSelect_Load(object sender, EventArgs e)
            {
                dgvProductSelect.Focus();
                dgvProductSelect.CurrentRow = dgvProductSelect.Rows[0];
                dgvProductSelect.CurrentColumn = dgvProductSelect.Columns["Quantity"];
                dgvProductSelect.Rows[0].Cells["Quantity"].Value = Convert.ToDecimal(rlbl_SalesQty.Text);
                dgvProductSelect.Rows[0].Cells["Quantity"].BeginEdit();
    }

    I think you got my problem.If you want any clarification,please let me know.

    Regards

    ABDUL HAFEEL

  13. Hristo
    Admin
    Hristo avatar
    1511 posts

    Posted 05 Jun 2017 Link to this post

    Hi Abdul,

    Thank you for writing.

    If I understand correctly, you would like to start editing the cell as soon as your form loads. The cell`s text will be selected by default. However, please consider setting the current row and column in the Shown event of your form: 
    protected override void OnShown(EventArgs e)
    {
        base.OnShown(e);
     
        this.radGridView1.CurrentRow = this.radGridView1.Rows[0];
        this.radGridView1.CurrentColumn = this.radGridView1.Columns[1];
     
        this.radGridView1.BeginEdit();
    }

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  14. Abdul
    Abdul avatar
    27 posts
    Member since:
    Jan 2017

    Posted 05 Jun 2017 in reply to Hristo Link to this post

    Thank You Hristo :) .It works correctly.

    Regards

    ABDUL HAFEEL

  15. Abdul
    Abdul avatar
    27 posts
    Member since:
    Jan 2017

    Posted 22 Jun 2017 Link to this post

    Hi ,

    I need to implement the row move up and down in RadGridView using RadButtons in WinForms.

    Regards
    ABDUL HAFEEL

  16. Hristo
    Admin
    Hristo avatar
    1511 posts

    Posted 23 Jun 2017 Link to this post

    Hi Abdul,

    Thank you for writing back.

    I would like to first point that we try to keep our threads focused on a single topic. In the future please consider posting your other questions separately.

    As to your actual question you can use the IsSelected and IsCurrent properties to select the next or previous rows: http://docs.telerik.com/devtools/winforms/gridview/rows/selected-rows-and-current-row.

    If you need to move the entire row up or down you can use my code snippet below: 
    private void btnDown_Click(object sender, EventArgs e)
    {
        this.MoveRow(true);
    }
     
    private void btnUp_Click(object sender, EventArgs e)
    {
        this.MoveRow(false);
    }
     
    private void MoveRow(bool forward)
    {
        BaseGridNavigator navigator = this.radGridView1.GridNavigator as BaseGridNavigator;
        var oldCurrent = this.radGridView1.CurrentRow;
        if (forward)
        {
            navigator.SelectNextRow(1);
        }
        else
        {
            navigator.SelectPreviousRow(1);
        }
         
        var newCurrent = this.radGridView1.CurrentRow;
     
        if (newCurrent != null && newCurrent.Index > -1)
        {
            for (int i = 0; i < oldCurrent.Cells.Count; i++)
            {
                object oldValue = oldCurrent.Cells[i].Value;
                object newValue = newCurrent.Cells[i].Value;
                newCurrent.Cells[i].Value = oldValue;
                oldCurrent.Cells[i].Value = newValue;
            }
        }
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top