Reputation: 23
I have a datagrid inside a win form and each has a V. Scroll bar. Now, by default the outer scroll bar is active and to activate the inner scroll, i have to click inside the datagrid. What I want is when the mouse is moved over the datagrid, the datagrid's scroll should be active and when my mouse is outside datagrid area the form's scroll should be active.
Upvotes: 0
Views: 575
Reputation: 899
You can set the ScrollBars property of the DataGridView on MouseEnter and MouseLeave, like this
private void dataGridView1_MouseEnter(object sender, EventArgs e)
{
DataGridView dataGridView = sender as DataGridView;
if (dataGridView != null)
{
dataGridView.ScrollBars = ScrollBars.Both;
}
}
private void dataGridView1_MouseLeave(object sender, EventArgs e)
{
DataGridView dataGridView = sender as DataGridView;
if (dataGridView != null)
{
dataGridView.ScrollBars = ScrollBars.None;
}
}
You can also just hardcode using the dataGridView in the handler since you'll probably know which one you want, but in case you need to handle this on multiple DataGridViews, you can use this.
Upvotes: 1