如何从组合框中选择一个值后,使用所选值刷新表单 [英] How to refresh form with selected value after selecting a value from combobox

查看:69
本文介绍了如何从组合框中选择一个值后,使用所选值刷新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows窗体应用程序上处理电影院项目。

我已经在组合框中放置了显示时间。我想从组合框中选择一个值

,然后刷新表格,以便显示该演出时间的分配座位。



问题是我怎样才能实现这个目标?

如何重新加载表单以便刷新所有内容但只保存选定的组合索引,以便我可以使用它来选择屏幕。



我尝试过:



i创建了另一个带有整数类型参数的表单函数,并从combobox selectedindexchanged函数调用它,但它没有工作

解决方案

你可以使用 .Refresh 方法在一个控件来刷新它和任何子控件。

所以一个简单的方法是将所有控件,除了ComboBox,放在面板 ,只刷新面板。

此外 .Invalidate 方法也很有用,请参阅:Co ntrol.Invalidate方法(System.Windows.Forms) [ ^ ]



您可以存储 ComboBox的选定值在使用 ComboBox.SelectedIndexChanged 事件的变量中,请参阅: ComboBox.SelectedIndexChanged事件(System.Windows.Forms) [ ^ ]


如果您在该组合框下进行硬编码或设置后续控制的值,那将会非常困难。更重要的是,这将是非常痛苦的。



我建议使用数据绑定方法,然后将特定对象绑定到表单本身。该对象及其值将用于显示表单上的内容,它将很简单,Windows Forms将最大限度地为您布置控件,视觉效果等工作!您需要做的就是提供数据。



当然,您可以使用 SelectedIndexChanged 事件,并在该事件内更新绑定对象(从数据源中选择,然后将其传递到那里)。



请从这里阅读更多内容, Windows窗体数据绑定| Microsoft Docs [ ^ ]

I am working on movie theater project on windows form application.
I have placed show times in combobox. I want to select a value from combobox
and then refresh the form so that it shows Allotment of seats for that show time.

The problem is how can i achieve this ?
How to reload a form so that everything is refreshed but only the selected INDEX of combobox is stored so that i can use is for selecting screen.

What I have tried:

i created another form function with an integer type parameter in it, and called it from the combobox selectedindexchanged function but it didnt work

解决方案

You can use the .Refresh method on a Control to refresh it and any child controls.
So an easy way would be to put all controls, except the ComboBox, in a Panel, and only refresh the panel.
Also the .Invalidate method can be useful, see: Control.Invalidate Method (System.Windows.Forms)[^]

You can store the selected value of the ComboBox in a variable using the ComboBox.SelectedIndexChanged Event, see: ComboBox.SelectedIndexChanged Event (System.Windows.Forms)[^]


That would be a lot tough if you go around hardcoding or setting the values of the follow-up controls under that combobox. And more than that, it would be extremely painful.

What I would recommend is, you should use Data Binding methods, then binding a particular objects to the form itself. That object and its values would be used to display the content on the form, it will be simple and Windows Forms will do maximum of the work for laying out the controls, visuals etc for you! All you will need to do would be to just provide the data.

Of course, you can use the SelectedIndexChanged event, and inside that event update the bound object (select from the data source, and then pass it over there).

Please read more from here, Windows Forms Data Binding | Microsoft Docs[^]


这篇关于如何从组合框中选择一个值后,使用所选值刷新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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