[英]CF TreeView - Selected Item when control loses focus
I know that "HideSelection" property is missing in CF. 我知道CF中缺少“ HideSelection”属性。 But i still need to handle situation when an item is selected that it remains selected (greyed) even when the control looses focus. 但是当选择一个项目时,即使控件失去焦点,我仍然需要处理使其保持选中状态(灰色)的情况。
I have tried using this peace of code, but with no success. 我尝试使用这种和平的代码,但没有成功。 I get an exception in GetFocus() method and i dont know what im doing wrong. 我在GetFocus()方法中遇到异常,我不知道自己在做什么错。
Any help is much appreciated ! 任何帮助深表感谢 !
[DllImport("User32.dll")]
static extern IntPtr GetFocus();
[DllImport("User32.dll")]
static extern Int32 GetWindowLong(IntPtr hwnd, Int32 integer1);
[DllImport("User32.dll")]
static extern IntPtr SetWindowLong(IntPtr hwnd, Int32 integer1, int integer2);
private bool doneOnce;
protected override void OnGotFocus(System.EventArgs e)
{
base.OnGotFocus(e);
if (this.itemsTreeView != null)
{
this.itemsTreeView.Focus();
if (doneOnce == false)
{
doneOnce = true;
IntPtr hWnd = GetFocus();
Int32 lS = GetWindowLong(hWnd, -16);
lS = lS | 0x20;
SetWindowLong(hWnd, -16, lS);
}
}
}
I have put this code in my "code behind" view that holds TreeView control. 我已将此代码放在保存TreeView控件的“代码隐藏”视图中。
Windows CE uses coredll.dll instead of user32.dll . Windows CE使用coredll.dll而不是user32.dll 。
Some functions are equal on both platforms, while some are not implemented for Compact Framework. 某些功能在两个平台上均相等,而某些功能未针对Compact Framework实施。 I usually check http://www.pinvoke.net for the declares. 我通常检查http://www.pinvoke.net上的声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.