如何处理 ComboBox 选定的索引更改? [英] How can I handle ComboBox selected index changing?

查看:21
本文介绍了如何处理 ComboBox 选定的索引更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含制造商列表的 ComboBox.当用户选择制造商时,下方的网格将填充所选制造商的数据.该数据可以修改.完成所有更改后,用户必须按保存"按钮.

I have a ComboBox that have a list of manufacturers. When a user selects a manufacturer, a grid below is populated with data for the chosen manufacturer. That data can be modified. The user has to press the Save button after all changes are done.

但用户可能忘记按保存并从组合框中选择另一个制造商,网格将填充另一个数据,因此之前的更改将丢失.

But the user can forget to press Save and select another manufacturer from the ComboBox and the grid will be populated with another data, so previous changes will be lost.

所以我需要在选择其他制造商之前询问用户是否要保存更改.

So I need to ask user if he wants to save changes before selecting another manufacturer.

我该怎么做?或者,您是否提供了另一种解决我的任务的方法(从另一个角度看)?

How can I do this? Or maybe you offer another way of solving my task (looking from another angle)?

推荐答案

您应该处理 ComboBox.SelectedIndexChanged 事件.类似的东西:

You should handle the ComboBox.SelectedIndexChanged event. Something like:

this.ComboBox1.SelectedIndexChanged += new system.EventHandler(ComboBox1_SelectedIndexChanged);

然后 ComboBox1_SelectedIndexChanged() 将在它更改时调用,您可以在该函数中更新制造商信息.在填充新信息之前保存旧信息.或者在保存之前提示用户是否真的要更改它.

Then ComboBox1_SelectedIndexChanged() will be called whenever it changes and you can update your manufacturer info in that function. Save the old info before populating the new info. Or prompt the user if they really want to change it before saving.

这篇关于如何处理 ComboBox 选定的索引更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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