Change visual element when grid has focus

4 posts, 1 answers
  1. Victoria
    Victoria avatar
    4 posts
    Member since:
    Apr 2013

    Posted 17 Apr 2013 Link to this post


    Hello, 

    I have a form with 4 grid controls on it, using office2010black theme. Each one is based on the one before it in a hierarchy mode but for work flow reasons I am not wanting to use a single grid. 

    It's working beautifully so far but the only complaint is the user doesn't know which grid has the focus before using arrows or enter for navigation. If I could change the row selection colour or even just stick a coloured border round the grid that has focus that would be great. 

    I tried changing the grid border in the grid's enter event but nothing changed I'm assuming as all the visual style examples I found in the forums seem to fire off the grid formatting event which by the time my user is clicking round the grids is long over. 

    Is there something I can change after the form is loaded and the grids are filled with data to indicate which one has focus that will fire off when the user clicks on or tabs into a grid?
  2. Answer
    Paul
    Admin
    Paul avatar
    60 posts

    Posted 19 Apr 2013 Link to this post

    Hello Victoria,

    Thank you for writing.

    What you can do is to set up some Padding for your grids, the number is in pixels and you can set the most suitable for you size. After that you can listen for the GotFocus event and change the BackColor property of your grids. Follows a sample which will give you a good idea of how to achieve all of the above. I have set some sample colors but you can change them in the most suitable for you way:
    public partial class Form1 : RadForm
    {
        public Form1()
        {
            InitializeComponent();
        }
     
        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is RadGridView)
                {
                    ctrl.Padding = new System.Windows.Forms.Padding(2);
                    ctrl.GotFocus += radGridView_GotFocus;
                }
     
            }
        }
     
        void radGridView_GotFocus(object sender, EventArgs e)
        {
            foreach (RadGridView grid in this.Controls)
            {
                if (grid == sender)
                {
                    grid.BackColor = Color.Red;
                }
                else
                {
                    grid.BackColor = Color.DarkGray;
                }
            }
        }
    }

    I hope this helps. Please do not hesitate to contact us for any further questions.

    Kind regards,
    Nikolay Aleksiev
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. Victoria
    Victoria avatar
    4 posts
    Member since:
    Apr 2013

    Posted 24 Apr 2013 Link to this post

    Thank you very much, with a little tweaking (I have all my grids in groupboxes) it is working nicely. Apologies for the delay in replying, I've been home with a sick kid.

    Victoria
  4. Paul
    Admin
    Paul avatar
    60 posts

    Posted 29 Apr 2013 Link to this post

    Hello Victoria,

    I am glad the solution worked. No worries about the delay. Hope your kid got well.

    Please do not hesitate to contact us, should you need any further assistance.

    Regards,
    Nikolay Aleksiev
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top