How do I scroll DataGrid to specified row index?

G

Guest

I want to know how to scroll a DataGrid so that a specific row index will be
visible to the user?
 
J

Jeffrey Tan[MSFT]

Hi Sharon,

Thanks for your post.

I am not sure why SendMessage does not work for you. As we negotiated in
the original post, this solution should work for you.(Actually, it works
well on my side.) If not, can you show me a little sample to demonstrate
the problem?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

I have this ElementsDataGrid class which is in ElementList class:

public class ElementList : System.Windows.Forms.UserControl
{
private class ElementsDataGrid : System.Windows.Forms.DataGrid
{
internal void ScrollToRow(int aRowNum)
{
this.GridVScrolled(this, new
ScrollEventArgs(ScrollEventType.LargeIncrement, aRowNum));
}
}

private bool m_autoScroll;
private InfraControls.ElementList.ElementsDataGrid m_DataGrid;

[Description("Determines whether the grid will scroll down when a new row
is added."),
Category("Layout")]
public override bool AutoScroll
{
get { return m_autoScroll; }
set { m_autoScroll = value; }
}

public void SetDataSource(DataView data)
{
m_DataGrid.DataSource = data;
data.AllowNew = false;
}

private void DoAutoScroll()
{
if( m_autoScroll )
{
m_DataGrid.ScrollToRow((m_DataGrid.DataSource as DataView).Count-1);
}
}

private void AddDefects(object aSender, ArrayList aDefectRows)
{
DoAutoScroll();
}
}

Defects are added to the DataSet, causing the ElementsDataGrid to be added
with more rows and invoking the AddDefects() that invoke the DoAutoScroll().
And the DoAutoScroll() is invoked causing the vertical scrollbar of the
ElementsDataGrid to move --> the focus is taken to the ElementsDataGrid. And
this is the problem I wish to avoid.

The code is larger then what I have posted in here, I couldn’t post all of
it in here (much too much). I hope this post can help resolving this problem.
 

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