Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

allow scroll with wheel mouse datagridview c#

private void DataGridView1_MouseEnter(object sender, EventArgs e)
        {
            DataGridView1.Focus();
        }

then Add Mouse wheel event in Load function 
DataGridView1.MouseWheel += new MouseEventHandler(DataGridView1_MouseWheel);

Finally Create Mouse wheel function

void DataGridView1_MouseWheel(object sender, MouseEventArgs e)
{
    int currentIndex = this.DataGridView1.FirstDisplayedScrollingRowIndex;
    int scrollLines = SystemInformation.MouseWheelScrollLines;

    if (e.Delta > 0) 
    {
        this.DataGridView1.FirstDisplayedScrollingRowIndex = Math.Max(0, currentIndex - scrollLines);
    }
    else if (e.Delta < 0)
    {
        if (this.DataGridView1.Rows.Count > (currentIndex + scrollLines))
            this.DataGridView1.FirstDisplayedScrollingRowIndex = currentIndex + scrollLines;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: monogame print 
Csharp :: csharp 3d array length 
Csharp :: docker Test a Connection using Curl 
Csharp :: give an alias in model .net 
Csharp :: how to customize xunit input 
Csharp :: what is float in c# 
Csharp :: conncet oracle database in c# visual studio 
Csharp :: c# substring find word 
Csharp :: redis cache repository .net 
Csharp :: how to get relative path in c# 
Csharp :: c# object is enum 
Csharp :: unity gun clipping through walls 
Csharp :: pricipal permission attribute in c# 
Csharp :: stop playing audiosource 
Csharp :: convert list to datatable c# 
Csharp :: c# get file author 
Csharp :: c# while true loop 
Csharp :: c# multiple inheritance 
Csharp :: how to use monitor from system.threading in c# 
Csharp :: c# temporary files 
Csharp :: ##[error]Dotnet command failed with non-zero exit code on the following projects 
Csharp :: display image script unity 
Csharp :: escape chars for regex c# 
Csharp :: unity GetNestedComponentsInChildren 
Csharp :: how to move mouse with c# 
Csharp :: save binary data to file c# 
Csharp :: Transpose Matrix C Sharp 
Csharp :: orderby c# 
Csharp :: access denied tring to save a file uwp xamarin 
Csharp :: AuthenticationTicket authenticationProperties C# .net 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =