Disable mouse wheel scrolling inside GridView

5 posts, 0 answers
  1. MJ14
    MJ14 avatar
    3 posts
    Member since:
    May 2010

    Posted 11 May 2010 Link to this post

    When in the edit mode, GridSpinEditor inside RadGridView allows the numeric value to change by scrolling mouse centerl scroll wheel. I need to disable this. How can I disable this feature?

    This feature lets the users to scrolldown to negative values, which is not desirable.

    Thanks.
  2. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 15 May 2010 Link to this post

    Hello Manu Juyal,

    To disable the MouseWheel scrolling you can change the behavior of the GridSpinEditor. To achieve that you can implement custom GridSpinEditor (inherited from the Telerik one).

    You will need two classes - for custom GridSpinEditor and custom GridSpinEditorElement:
    public class CustomGridSpinEditor : GridSpinEditor
    {
        protected override RadElement CreateEditorElement()
        {
            return new CustomGridSpinEditorElement();
        }
    }
     
    public class CustomGridSpinEditorElement : GridSpinEditorElement
    {
        public CustomGridSpinEditorElement()
        {
            base.ButtonDown.Click += new EventHandler(ButtonDown_Click);
            base.ButtonUp.Click += new EventHandler(ButtonUp_Click);
        }       
     
        private void ButtonDown_Click(object sender, EventArgs e)
        {
            base.PerformStep(-Step);
        }
     
        private void ButtonUp_Click(object sender, EventArgs e)
        {
            base.PerformStep(Step);
        }
     
        public override void PerformStep(decimal step)
        {
        }
    }

    When you have the custom editor you can provide it to the RadGridView:
    radGridView1.EditorRequired += new EditorRequiredEventHandler(radGridView1_EditorRequired);
     
    void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (e.EditorType == typeof(GridSpinEditor))
        {
            e.EditorType = typeof(CustomGridSpinEditor);
        }
    }

    This way you will disable the MouseWheel scrolling for the GridSpinEditors.

    You mentioned that you need to prevent the user from setting negative values for the values in that column. We could advice you to ensure that by defining minimum value to the column with the GridSpinEditor. You can use the following code sniped:
    GridViewDecimalColumn column = (GridViewDecimalColumn)radGridView1.Columns[0];
    column.Minimum = 0;

    Using the second approach does not require preventing the MouseWheel scrolling.

    Please, let us know if you have further questions.

    Regards,
    Alexander
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gabi
    Gabi avatar
    1 posts
    Member since:
    Jun 2010

    Posted 19 May 2011 Link to this post

    Hi,

    The above mentioned solution is working well for GridSpinEditor, but how can you disable the mousewheel functionality in the RadDateTimeEditor?

    Thank you.

    Best regards,
    -Gabriella
  5. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 25 May 2011 Link to this post

    Hello Gabi,

    It is not possible to disable the mouse wheel handling in the RadDateTimeEditor, however you can use the approach which Richard suggested in this forum thread:

    private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (e.EditorType == typeof(RadDateTimeEditor))
        {
            e.EditorType = typeof(CustomDateTimeEditor);
        }
    }
     
    public class CustomDateTimeEditor : RadDateTimeEditor
    {
        protected override RadElement CreateEditorElement()
        {
            CustomDateTimeEditorElement editor = new CustomDateTimeEditorElement();
            RadDateTimePickerCalendar calendarBehavior = editor.GetCurrentBehavior() as RadDateTimePickerCalendar;
     
            if (calendarBehavior != null)
            {
                calendarBehavior.Calendar.ShowFooter = true;
                editor.CalendarSize = new Size(200, 200);
            }
     
            return editor;
        }
    }
     
    public class CustomDateTimeEditorElement : RadDateTimeEditorElement
    {
        public CustomDateTimeEditorElement()
        {
            base.TextBoxElement.TextBoxItem.MouseWheel += new MouseEventHandler(TextBoxItem_MouseWheel);
        }
     
        private void TextBoxItem_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta > 0)
            {
                SendKeys.Send("{DOWN}");
            }
            else
            {
                SendKeys.Send("{UP}");
            }
        }
    }

    I hope it helps.

    Best regards,
    Alexander
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  6. Jose
    Jose avatar
    4 posts
    Member since:
    Jan 2014

    Posted 03 Sep 2015 Link to this post

    For a decimal cell

    Dim colSetup As GridViewDecimalColumn = TryCast(objRGV.Columns(FieldName), GridViewDecimalColumn)
    If Not colSetup Is Nothing Then colSetup.Step = 0

Back to Top
UI for WinForms is Visual Studio 2017 Ready