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

Custom zoom

5 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomáš
Top achievements
Rank 1
Iron
Tomáš asked on 10 Mar 2021, 04:29 PM

Hello,

my task was to enable zoom of GridView using mouse wheel + Ctrl key. I implemented it with partial success. I am not able to correctly resize some parts of the grid - see attached pic with red rectangles. I can provide a sample project. And a subquestion - is it possible to disable scrolling while the Ctrl Key is pressed?

Thanks in advance for help.

Tomáš

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Mar 2021, 08:05 AM
Hello, Tomáš,

According to the provided screenshot, it seems that the Font for the grid cells is enlarged. I suppose that this is applied in the ViewCellFormatting event. Please have in mind that the rows' height wouldn't be automatically adjusted when you change the font size. That is why I would recommend you to set the RadGridView.AutoSizeRows property to true and then the rows' height will be adjusted to fit the content. The attached gif file illustrates the achieved result on my end.

If you want to disable the scrolling behavior when the Control key is pressed, you can use the following custom implementation:  

        public class CustomGrid : RadGridView
        {
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadGridView).FullName;
                }
            }
            protected override void OnMouseWheel(MouseEventArgs e)
            {
                if (System.Windows.Forms.Control.ModifierKeys == Keys.Control)
                {
                    return;
                }
                base.OnMouseWheel(e);
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tomáš
Top achievements
Rank 1
Iron
answered on 11 Mar 2021, 10:32 AM

Hello, Dess,

thanks for your quick reply. Yes, the Font is enlarged. It's applied in the FontChanged event, but I suppose it doesn't matter a lot. The AutoSizeRows property seemed like a good idea but it works only for single line strings. It's logical that for multiline text the row gets higher to show its full content. But that's the problem - I don't want this behavior. Users can store quite long texts in some columns and it wouldn't look good. The grid serves as a quick overview, it's not important to show whole texts, just the first line. I have Multiline and WrapText set to false, but with AutoSizeRows, it always shows everything. So I tried to set row height manually, which worked only partially as I wrote in the first post.

I hope I described my intentions in an understandable way.

I didn't try the scrolling suggestion yet, but it seems like it should do the trick, thanks.

 

Regards,

Tomáš

0
Tomáš
Top achievements
Rank 1
Iron
answered on 12 Mar 2021, 08:55 AM

Hello, Dess,

I just wanted to inform you that I found a way how to resize all the parts of grid. So consider this solved. But another issue popped up - when I use a Metro or Metro Blue theme, changing the font size doesn't have any effect on the grid - the font size remains still the same.

Any ideas on this? Thanks

Tomáš

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Mar 2021, 11:26 AM
Hello, Tomáš,

I am glad that you have found a suitable approach for sizing the rows to show the desired part of the content. 

As to the question at hand, since I am not familiar with the exact font implementation that you have on your end, it wouldn't be easy to determine why the font doesn't take effect when you change the theme to Metro or Metro Blue.

I would like to note that the recommended way to customize the font and its size is to handle the ViewCellFormatting event. A sample approach is demonstrated below: 
        Font f = new Font("Arial", 10f, FontStyle.Regular);
        private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            e.CellElement.Font = f;
        }

You can manage the font size dynamically during the application's execution. Once the font is edited, you need to force the ViewCellFormatting event by calling the MasterTemplate.Refresh method.

In case you are still experiencing any further difficulties, it would be greatly appreciated if you can provide more details about the exact implementation that you have on your end. Thus, we would be able to integrate this approach in my sample project and provide further assistance. Thank you in advance

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tomáš
Top achievements
Rank 1
Iron
answered on 15 Mar 2021, 02:07 PM

Hello, Dess,

thank you, the ViewCellFormatting event was the right place, the font changes correctly now. I am not sure why for all other themes it was good enough to just set the new font like this: ragGridView1.Font = new Font("Arial", 10f, FontStyle.Regular), but I guess I don't have to know everything.

Thanks again for your time.

Regards

Tomáš

Tags
GridView
Asked by
Tomáš
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Tomáš
Top achievements
Rank 1
Iron
Share this question
or