组合框 - 键入选择,然后单击焦点 - 不选择键入的项 [英] Combo box - typing selection then clicking out of focus - doesn't select the typed item

查看:121
本文介绍了组合框 - 键入选择,然后单击焦点 - 不选择键入的项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到组合框的问题。我有一个事件处理程序 OnClick 根据选择什么项刷新数据。问题是这种情况发生时:

I'm having an issue with the combo box. I have an event handler for OnClick which refreshes data based on what item was selected. The problem is when this scenario occurs:


  1. 下拉组合框列出各种选项

  2. 键入键盘以查找匹配项

  3. 组合框更改此选择并调用 OnClick 事件

  4. 由于此选择/活动,我的屏幕会刷新

  5. 单击组合框之外的某处可将焦点移开。

  6. 即使 OnClick 已调用

  7. ,组合框也会返回上一个选择。即使组合框更改回之前的选择, OnClick 未再次调用

  8. 此后,组合框显示的值不同于我的数据实际代表的值

  1. Drop-down the combo box to list the various options
  2. Type on the keyboard to find a matching item
  3. Combo box changes this selection and calls the OnClick event
  4. My screen refreshes due to this selection / event
  5. Click somewhere outside of the combo box to take the focus away from it
  6. Combo box goes back to the previous selection, even though OnClick was already called
  7. Even though Combo box changed back to prior selection, OnClick isn't called again
  8. After this, Combo Box shows different value than what my data actually represents

所以当你打开一个组合框,并在键盘上键入几个字母,以找到下拉列表中的项目, OnClick 被触发,刷新我的屏幕。但是当你点击组合框之外的某处(从而使焦点远离它)时,组合框会变回之前选择的任何值,而不是我键入的值。同时, OnClick 事件不会触发,因此组合框显示的错误值与我在屏幕上加载的值不同。

So when you open a combo box, and type a few letters on the keyboard to find the item in the drop-down list, OnClick is fired which refreshes my screen. But when you click somewhere outside the combo box (thus taking the focus away from it), the combo box changes back to whatever value was previously selected, instead of what I had typed. And at the same time, the OnClick event isn't fired, so the combo box shows the incorrect value compared to what I had loaded on the screen.

在这种在键盘上键入项目的情况下,如何使组合框保留在所选项目上?

How do I make the combo box stay on the selected item in this scenario of typing the item on the keyboard?

推荐答案

在我的代码中,我使用 OnCloseUp 事件处理。实际上,我使用一个子类combo为我的下拉列表,它们覆盖了 Change CloseUp 方法:

In my code, I deal with this using the OnCloseUp event. Well, in fact I'm using a sub-classed combo for my drop-down lists and they override both the Change and CloseUp methods:

procedure TMyDropDownList.Change;
begin
  RespondToChange;
  inherited;
end;

procedure TMyDropDownList.CloseUp;
begin
  RespondToChange;
  inherited;
end;

RespondToChange 方法会对新 ItemIndex 值。如果在组合下降时对每一个变化做出反应是昂贵的,那么你可以考虑省略从 Change RespondToChange code>方法。

The RespondToChange method reacts to the new ItemIndex value. If it is expensive to react to every single change whilst the combo is dropped down, then you might consider omitting the call to RespondToChange from the Change method.

这篇关于组合框 - 键入选择,然后单击焦点 - 不选择键入的项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆