Why won't you give me your scrollbars?! I hate you, TreeView!

S

sklett

A little dramatic maybe, but I've just finished my pass on the "UI Polish"
and only one things remains (well, I guess I haven't finished then!)

Vertical Scrollbar position. Doh!
Part of my code clears a Node's nodes, then rebuilds them all. When this
happens, the scrollbar position is not restored (expected - I'm happy to do
it.. if I can!) and I don't see how I can do that. I have checked the docs,
google, friends, etc. No love. Is it possible?

Teach me, wise one(s)...
 
F

Frans Bouma [C# MVP]

sklett said:
A little dramatic maybe, but I've just finished my pass on the "UI
Polish" and only one things remains (well, I guess I haven't finished
then!)

Vertical Scrollbar position. Doh!
Part of my code clears a Node's nodes, then rebuilds them all. When
this happens, the scrollbar position is not restored (expected - I'm
happy to do it.. if I can!) and I don't see how I can do that. I
have checked the docs, google, friends, etc. No love. Is it
possible?

Teach me, wise one(s)...

Set 'EnsureVisible' on the treenode to true.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
R

rowan

I had a similiar issue in a datagrid which I had to remember the value
and find it again. The scroll isn't readily available so I had to
override the normal grid to make the scroll accessible...

// When the frmEditShipment form closes, it will set the
// lastEvent and lastRecord strings so that we can
// this form can autonavigate to the record and re-select it.
// this way, even having several records open you can
// close anyone and be brought to it's matching line entry.

if(lastEvent == "Edit")
{
//lastEvent = "";
runData(true);
// runData has reset the grid, due to rebinding
// now set the grid back to the same location
// the BindingManagerBase gives you a link between
// the displayed records and the dataset records.
// use this to scroll to and select the row
BindingManagerBase bmb =
dgRec.BindingContext[dgRec.DataSource,"trucks"];
for(int i = 0; i < bmb.Count;i++)
{
// use the Manager as a cursor and move forward through it.
bmb.Position = i;
// check each row's barcode to see if it's the right one
DataRow dr = ((DataRowView)bmb.Current).Row;
if(lastRecord == Convert.ToString(dr["barCodeNumber"]))
{
// had to override the grid to get access to the scroll
// also had to use the overridden object as the grid,
// instead of the default Forms.DataGrid
// It now exists in MyDataGrid.cs
dgRec.ScrollToRow(i);
dgRec.CurrentCell = new DataGridCell(i,1);
dgRec.Select(i);
break; // don't look anymore
}
}

}


Maybe something similiar will help you get it working...

public class MyDataGrid : DataGrid
{
public MyDataGrid()
{
//
// TODO: Add constructor logic here
// This class is dirived from DataGrid to all
// the private method GridVScrolled to be
// accessed, allowing us to scroll the grid
// back to it's last row after a refresh
// of the data and a rebinding
//

}
public void ScrollToRow(int row)
{
if(this.DataSource != null)
{
this.GridVScrolled(this,new
ScrollEventArgs(ScrollEventType.LargeIncrement,row));
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top