是否有一个WinForm的一个C#组合框一个更新前 [英] Is there a BeforeUpdate for a C# ComboBox on a Winform

查看:250
本文介绍了是否有一个WinForm的一个C#组合框一个更新前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自VBA的世界,记得有一个更新前拨打我可以做一个组合框。现在我在C#(和爱它),我想知道是否有一个更新前呼吁为组合框上一个Winform的?

I come from the VBA world, and remember there was a BeforeUpdate call I could make on a combobox. Now I am in C# (and loving it) and I was wondering is there a BeforeUpdate call for a ComboBox on a Winform?

我可以让一个不可见的文本框和存储我需要有和更新后,看那个盒子是我需要的信息,但我希望有一个simplier解决方案。

I can make an invisible textbox and store the info I need there and after the update, look at that box for what I need, but I was hoping there was a simplier solution.

推荐答案

您可以考虑 SelectionChangeCommited

从MSDN:

SelectionChangeCommitted升至
只有当用户更改组合
框选项。不要使用
的SelectedIndexChanged或
SelectedValueChanged捕获用户
的变化,因为这些事件也$当选择编程方式更改
B $ B提升。

SelectionChangeCommitted is raised only when the user changes the combo box selection. Do not use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically.

当您设置您的组合框允许用户虽然在文本框中键入这是行不通的。此外,它不会告诉你'最后'选择的项目是什么。你将不得不缓存此信息。不过,你不需要来存储你的信息在一个文本框。您可以使用一个字符串。

This won't work when you have set your combobox to allow the user to type in the textbox though. Also, it won't tell you what the 'last' selected item was. You will have to cache this information. However, you don't need to store your information in a textbox. You can use a string.

这篇关于是否有一个WinForm的一个C#组合框一个更新前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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