如何在不窃取焦点的情况下使用DataGrid AutoScroll? [英] How to have DataGrid AutoScroll without stealing the focus ?
问题描述
我在我的DataGrid控件中添加了一个自动滚动功能,如下所示:
private void DoAutoScroll()
{
DataView dv = m_DataGrid.DataSource as DataView;
DataGridCell cell = m_DataGrid.CurrentCell;
cell.RowNumber = dv.Count;
m_DataGrid.CurrentCell = cell ;
}
但是这段代码的最后一行是关注当前的
单元格,它是偷的来自使用焦点的其他控件的焦点。
如何在不停留焦点的情况下仍然拥有自动滚动功能?
如果在我打电话给上面的DoAutoScroll()之前我是新的焦点,那么我可以给焦点回馈。
---------
谢谢
Sharon
I have added an auto scroll feature to my DataGrid control like this:
private void DoAutoScroll()
{
DataView dv = m_DataGrid.DataSource as DataView;
DataGridCell cell = m_DataGrid.CurrentCell;
cell.RowNumber = dv.Count;
m_DataGrid.CurrentCell = cell;
}
But this the last line of this code is putting the focus on the current
cell, and it steal the focus from other control that uses the focus.
How can I still make have the auto scroll feature without stilling the focus?
If I new how has the focus before I call to the above DoAutoScroll(), then I
could give the focuses back.
---------
Thanks
Sharon
推荐答案
嗨沙龙,
感谢您的帖子。
是的,我想我们可以使用Form.ActiveControl属性获取并设置
f ocused控件,代码如下:
private void DoAutoScroll()
{
CurrencyManager cm = this.dataGrid1.BindingContext [ this.dataSet11.jobs,
""]作为CurrencyManager;
DataGridCell cell = this.dataGrid1.CurrentCell;
cell.RowNumber = cm.Count-1;
this.dataGrid1.CurrentCell = cell;
}
private void invokemethod()
{
控制focusControl = this.ActiveControl;
DoAutoScroll();
this.ActiveControl = focusControl; < br $> b $ b}
希望这会有所帮助
祝你好运,
Jeffrey Tan
Microsoft在线合作伙伴支持
安全! - www.microsoft.com/security
此帖子按原样提供没有保证,也没有授予任何权利。
Hi Sharon,
Thanks for your post.
Yes, I think we can use Form.ActiveControl property to get and set the
focused control, code like this:
private void DoAutoScroll()
{
CurrencyManager cm = this.dataGrid1.BindingContext[this.dataSet11.jobs,
""] as CurrencyManager;
DataGridCell cell = this.dataGrid1.CurrentCell;
cell.RowNumber = cm.Count-1;
this.dataGrid1.CurrentCell = cell;
}
private void invokemethod()
{
Control focusControl=this.ActiveControl;
DoAutoScroll();
this.ActiveControl=focusControl;
}
Hope this helps
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.
另外,在我的代码片段中,如您所见,我没有使用DataView
方式,但使用CurrencyMananger获取行数。另外,我们应该使用
cm.Count-1来获取最后一行。
谢谢
此致,
Jeffrey Tan
Microsoft在线合作伙伴支持
安全! - www.microsoft.com/security
此帖子按原样提供没有保证也没有授予任何权利。
Additionally, in my code snippet, as you can see, I did not use DataView
way, but use the CurrencyMananger to get the row count. Also, we should use
cm.Count-1 to get the last row number.
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.
非常感谢Jeffrey的帮助。
它''非常好,我可以告诉谁有焦点所以我将能够恢复
它。但是它仍然会让焦点从控制中闪烁,而b / b
偷走焦点,这会让用户感到非常不舒服。
因此我希望使用DataGrid垂直滚动条,所以我做了以下
:
++(m_DataGrid.VScrollBar.Maximum);
m_DataGrid.VScrollBar.Value = m_DataGrid.VScrollBar.Maximum;
但是导致滚动条向下移动,但仍然可能在下面并且
没有像他们那样显示。
如何使用
DataGrid的垂直滚动条一直向下滚动?
---------
谢谢
Sharon
Thank a lot Jeffrey for your help.
It''s very good that I can tell who has the focus so I''ll be able to restore
it. But It''s still causing the focus to blink away from the control that I
steal the focus from, and it causes the user very uncomfortable.
Therefore I wish to use the DataGrid vertical Scrollbar, So I did the
following:
++(m_DataGrid.VScrollBar.Maximum);
m_DataGrid.VScrollBar.Value = m_DataGrid.VScrollBar.Maximum;
But is causes the scrollbar to move down, but still may line are below and
not shown like they should.
How can I scroll all the way down using the vertical scrollbar of the
DataGrid?
---------
Thanks
Sharon
这篇关于如何在不窃取焦点的情况下使用DataGrid AutoScroll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!