开发者

Linking two different controls

I have shown a part of my Winform application here. The Top most part is the Timeline, The Vertical Lines there indicate the appearance of certain type of messages at those time Instants. Its is linked to the contents of the datagridview which is linked to a SQLite Database

Linking two different controls

In normal operation what happens is I load a database. And The database is shown in the datagrid view and then, different type of messages are marked in the Timeline by red/blue/yellow line. The Timeline 开发者_如何学Ccan be scrolled horizontal by dragging the mouse across.. (i.e It doesnt have an explicit scroll bar)

What I need to do now is that.. If I right click a point on the timeline and click on Goto LogLine, The DGV down should automatically scroll down to that line in the DGV that has the same timestamp.

How can this be done??


All you need to do is set the DataGridView.SelectedCell to the one of interest, maybe the first cell in the row you have discovered if of interest. Then the DataGridView will automatically being that cell into view by scrolling as needed.


you can do this by setting VerticalScrollingOffset of the DataGridView in the Scroll Event using Reflection

include namespace System.Reflection

PropertyInfo verticalOffset = dataGridView2.GetType().GetProperty("VerticalOffset", BindingFlags.NonPublic | BindingFlags.Instance);
verticalOffset.SetValue(dataGridView2, dataGridView1.VerticalScrollingOffset, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜