473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DataGrid mismatch between grid and scrollbar slider position


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
--
Nov 22 '05 #1
0 809

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard van Wegen | last post by:
Dear All I want to use the horizontal scrollbar control, but I can't figure out how to change the width of the slider, i.e. the bit that you drag left & right. With other controls (eg Textbox),...
0
by: Frnak McKenney | last post by:
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...
1
by: john sutor | last post by:
Does anyone know if you can display vertical scroll or horizontal scroll bars on the datagrid ???
1
by: gmtongar | last post by:
Hi, I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same,...
3
by: Hans [DiaGraphIT] | last post by:
how can I keep track of the first visble line in my datagrid when I drag the vertical scrollbar up or down? To clairfy my need... An example: I wish to set CurrentRowIndex to be the first...
9
by: web1110 | last post by:
Hi y'all, I have resized the columns in a DataGrid and I want to set the width of the DataGrid to fit the columns. Just summing the column widths is too short due to the grid and gray row...
2
by: Gene Hubert | last post by:
I'm assigning a new datasource (a datatable) to a datagrid that is aready displayed in a form. Then I assign a new value to CurrentRowIndex. The datagrid always scrolls so that the new current...
3
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My...
1
by: 123456prakash | last post by:
Does anyone know if it is possible to set programmatically the position of a JScrollPane vertical scrollbar slider? I load a some components like textfield editorpane labels etc into a panel...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.