By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Mouse Wheel Scrolling Causes DataGrid To Loose Focus

P: n/a
Hi All

I got a datagrid and a ComboBox on a form. I populate the combobox with
years for all the data avaiable. When the user chooses a year the datagrid
is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel it work
for 2 wheel clicks and then for some reason the focus jumps to the combobox
and the year is then changes there for causing the data to change and errors
.... sometimes.

Anybody experience this or know how to fix it...

Thanks
Bryan
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I had something similar with textbox and datagrid on same panel.
I used MouseEnter event to select datagrid

myDataGrid.Select();

For me it did the trick. How's it for you?

Note, that I was updating content of grid on mouse wheel. It might've been
related to dynamic change of data there.

HTH
Alex

"Bryan Masephol" <ma******@uwec.edu> wrote in message
news:OO**************@TK2MSFTNGP11.phx.gbl...
Hi All

I got a datagrid and a ComboBox on a form. I populate the combobox with
years for all the data avaiable. When the user chooses a year the datagrid is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel it work for 2 wheel clicks and then for some reason the focus jumps to the combobox and the year is then changes there for causing the data to change and errors ... sometimes.

Anybody experience this or know how to fix it...

Thanks
Bryan

Nov 15 '05 #2

P: n/a
Hmmm

Thanks for the input Alex but it seemed to make things worse. Even though I
select the datagrid when the mouse enters it still wants to jump to my
combobox. Very weird. I'll keep trying things and post what I find.

If anyone else had problems like this please contribute.

Bryan

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
I had something similar with textbox and datagrid on same panel.
I used MouseEnter event to select datagrid

myDataGrid.Select();

For me it did the trick. How's it for you?

Note, that I was updating content of grid on mouse wheel. It might've been
related to dynamic change of data there.

HTH
Alex

"Bryan Masephol" <ma******@uwec.edu> wrote in message
news:OO**************@TK2MSFTNGP11.phx.gbl...
Hi All

I got a datagrid and a ComboBox on a form. I populate the combobox with
years for all the data avaiable. When the user chooses a year the

datagrid
is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel it

work
for 2 wheel clicks and then for some reason the focus jumps to the

combobox
and the year is then changes there for causing the data to change and

errors
... sometimes.

Anybody experience this or know how to fix it...

Thanks
Bryan


Nov 15 '05 #3

P: n/a
I normally wouldn't reply to posts this old, but they seem really
similar
to what I'm working on...

"Bryan Masephol" <ma******@uwec.edu> wrote:
I got a datagrid and a ComboBox on a form. I populate the combobox
with years for all the data avaiable. When the user chooses a year
the datagrid is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel
it work for 2 wheel clicks and then for some reason the focus jumps
to the combobox and the year is then changes there for causing the
data to change and errors ... sometimes.
I have a similar setup, though I have TWO datagrids. If I click in
the bottom grid, then just like happened to Bryan, after 2 wheel
clicks the focus shifts to the ComboBox. If I click in the top grid,
then after 2 clicks, focus moves to the lower grid, then to the
ComboBox on the next click.

AlexS replied to Bryan: I had something similar with textbox and datagrid on same panel.
I used MouseEnter event to select datagrid

myDataGrid.Select();

For me it did the trick. How's it for you?


It's unclear what component's event I'm supposed to do that on, but
doing it on the grid does squat for me.

AlexS later suggested that perhaps Bryan had a DataSource being
shared between the ComboBox and DataGrid, but that doesn't seem to
be the case in my application (the ComboBox always gets a new
DataSource). But it wasn't clear if AlexS meant literally the
DataSouce component or a more general "data source" and possibly
therefore meaning something else...
Does anyone else have any (other) ideas/solutions?

Nov 16 '05 #4

P: n/a
I wrote:
"Bryan Masephol" <masep...@uwec.edu> wrote:
I got a datagrid and a ComboBox on a form. I populate the combobox
with years for all the data avaiable. When the user chooses a year
the datagrid is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel
it work for 2 wheel clicks and then for some reason the focus jumps
to the combobox and the year is then changes there for causing the
data to change and errors ... sometimes.
I have a similar setup, though I have TWO datagrids. If I click in
the bottom grid, then just like happened to Bryan, after 2 wheel
clicks the focus shifts to the ComboBox. If I click in the top grid,
then after 2 clicks, focus moves to the lower grid, then to the
ComboBox on the next click.


I hate following up my own posts, but I just noticed something --
it's not "2 wheel clicks" before it changes focus, but rather it's
when the selected row scrolls out of the "viewport".

Also, it's changing focus to the next component in TabOrder; I set
TabStop to false for the two DataGrids and the ComboBox and now
focus jumps to a TextBox (which I'd like to keep tab-able along
with the other components around it) when the selected row scrolls
out of the DataGrid's viewable area.

I have some code to select the whole row instead of just the cell
clicked in, as shown below -- is there maybe something to this
that's screwing things up? I don't think so, since I commented
that out of the DataGrids' MouseUp events, but who knows.

Any ideas?

private void DataGrid_SelectFullRow(DataGrid grid,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = grid.HitTest(pt);

if (hti.Type == DataGrid.HitTestType.Cell)
{
grid.CurrentCell = new DataGridCell(hti.Row, hti.Column);
grid.Select(hti.Row);
}
}

Nov 16 '05 #5

P: n/a
Solved... For posterity:

I wrote:
"Bryan Masephol" <masep...@uwec.edu> wrote:
I got a datagrid and a ComboBox on a form. I populate the combobox
with years for all the data avaiable. When the user chooses a year
the datagrid is populated with the specific years information.

Problem... when the users scrolls the datagrid with the mouse wheel
it work for 2 wheel clicks and then for some reason the focus jumps
to the combobox and the year is then changes there for causing the
data to change and errors ... sometimes.
it's not "2 wheel clicks" before it changes focus, but rather it's
when the selected row scrolls out of the "viewport".
After two days, I finally managed to come up with the right search
criteria to find an answer...

From: http://www.dotnetforums.net/t78467.html
Private Sub DataGrid1_MouseWheel(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs)
Handles DataGrid1.MouseWheel
DataGrid1.Focus()
End Sub


I'm using C#, but the idea was clear enough, and I got it working.

....Though Visual Studio (7.1.3088 with .Net 1.1.4322) doesn't seem
to give me the MouseWheel event in the visual builder, so I had to
add it manually to the "Windows Form Designer generated code",
which always makes me a little nervous since it says "do not modify
the contents of this method with the code editor". I don't know if
Visual Studio is set up incorrectly, or if later versions list this
event, or what, but ugh...

In that section:

this.dataGridComponent.MouseWheel += new
System.Windows.Forms.MouseEventHandler(this.DataGr id_MouseWheel);

....and elsewhere:

private void DataGrid_MouseWheel(object sender,
System.Windows.Forms.MouseEventArgs e)
{
((DataGrid) sender).Focus();
}

....and no scrolling with the mouse wheel works.

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.