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

Disable mouse wheel scrolling inside GridView

4 Answers 336 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MJ14
Top achievements
Rank 1
MJ14 asked on 11 May 2010, 07:33 PM
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.

4 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 15 May 2010, 12:03 PM
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.
0
Gabi
Top achievements
Rank 1
answered on 19 May 2011, 08:22 AM
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
0
Alexander
Telerik team
answered on 25 May 2011, 05:27 AM
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.
0
Jose
Top achievements
Rank 1
answered on 03 Sep 2015, 03:33 PM

For a decimal cell

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

Tags
GridView
Asked by
MJ14
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Gabi
Top achievements
Rank 1
Jose
Top achievements
Rank 1
Share this question
or