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);
}
}