I have a (small) multi-table database application which allows
edits, print reports, and has two scrolling screen displays which
show information merged from multiple tables.
I'm having trouble with one of the scrolling displays which is
implemented as a DataGrid with several custom DataGridColumnStyles.
When the Form containing the DataGrid is made visible the initial
rows of the DataGrid's DataView source display as one might expect.
Unfortunately, the scroll bar is positioned at the bottom of its
track, and as soon as it is touched with the mouse the displayed
portion of the DataGrid "jumps" down to match the slider's position.
Using the debugger to dig into the DataGrid just before it displays,
I find that its CurrentRowIndex is (as one might expect) 0, and the
VertScrollBar's Value is around 142 for a table of 153 rows. The
DataGrid's exterior does seem to correctly reflect its internal
state... I just can't figure out how it could wind up in this
state.
Originally I didn't see this problem. The DataGrid always showed up
with both the grid and the scrollbar at the top of the DataView.
Trouble is, <grin> it wasn't correct -- it wasn't keeping in step
with changes to the database.
My current approach creates a DataGrid display by issuing a fairly
complex SELECT to re-fill the underlying DataTable each time the
Form containg the DataGrid becomes visible. I add a couple of extra
DataColumns, fill them, and return a DataView based on the result.
I then point the DataGrid at the new DataView; the code looks
something like the following:
DataView dv_dg;
private void FormXX__VisibleChanged(...
if ( ((Form)sender).Visible == true ) {
dv_dg = GetNewDataView();
dataGrid1.SuspendLayout();
dataGrid1.SetDataBinding(dv_dg,"");
dataGrid1.ResumeLayout(false);
//nope dataGrid1.Update();
//nope dataGrid1.DataSource = dv_dg;
//nope dataGrid1.CurrentRowIndex = 0;
//nope dataGrid1.Refresh();
....
(The "//nope" lines are unsuccessful things I've tried in an attempt
to get the scroll bar slider to position correctly)
So... does anyone know what it is that controls where the
VertScrollBar slider winds up when you point a DataGrid at a new
DataSource?
It's true that I could create my own DataGrid class and forcibly
stomp on the slider, and if I con't come up with any other ideas
that's what I'll have to do. However, I'm a little uncomfortable
doing this without understanding why the problem is occurring: it
feels too much like restoring power by screwing a burnt-out fuse
down on a penny. It's a workaround, and you never know when the
underlying cause might come back to bite you in some sensitive
portion of your anatomy. <grin>
Has anyone ever seen anything like this before? Does anyone have any
idea what might make a DataGrid behave this way?
Any suggestions will be welcomed.
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)
--
Q: What are the benefits of speaking to your fans via e-mail?
DNA: It's quicker, easier, and involves less licking.
-- Douglas Adams / The Salmon of Doubt
--