如何获得Combobox价值...... [英] How to Get Combobox value...

查看:90
本文介绍了如何获得Combobox价值......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Employyee管理的小应用程序...

在这个应用程序中,我必须使用名为 RefID 的主要数据更新三个差异数据库...

RefID 仅在组合框中....在Combobox中我有 RefID 列表...基于Combobox值的选择。 。数据库更新......但数据库是另一种形式... 我必须将选定的组合框值传递给另一种形式 ....但它不可能......



请帮帮我...我试试3天......



先谢谢

I am doing a small application that Employyee management...
In this application i have to update the three diff Databases using a primary called RefID...
The RefID is at combobox only....In Combobox i am having the RefID list...Basing on the selection of Combobox value..The databases updated...But The database is in another form...I have to pass the selected combobx value to another form....But it doesn''t possible...

Please help me...I am trying this from 3 days...

Thanks In advance

推荐答案

这是微不足道的。 comobobox具有SelectedText和SelectedValue属性。您可以将它们传递到任何您喜欢的地方,或者使用委托来连接两个表单,以便可以调用另一个表单从中获取值。
This is trivial. The comobobox has a SelectedText and a SelectedValue property. You can pass these through anywhere you like, or use delegates to hook up two forms so one can call another to get a value from it.


有许多方法可以在两者之间传递数据形式。你应该首先考虑''Form''只是一个类,如果你知道如何在类之间传递数据,那就是它,你完成了。



在开始编码之前,这些是您应该了解的基本内容。你应该有足够的基础来成为一名优秀的程序员,否则你最终会陷入混乱。



要回答你的问题,你可以在表单中声明一个公共变量用于设置组合框读取值的类。正如克里斯在评论中提到的,我们不知道如何调用表单或何时显示表单。但以下解决方案可以帮助您解决问题



假设

你想通过第二个表单显示之前的组合值

There are many ways that you can pass data between Forms. You should first consider ''Form'' is nothing but a class and if you know how to pass data between the classes then that''s it, your done.

These are very basic things you should know before you start coding. You should be strong enough with the basics to become a good programmer otherwise you end up with mess.

To answer your question, you can declare a public variable in your form class to set the Combo Box read value. As Chris mentioned in his comment we dont know how your forms are invoked or when it gets displayed. but the following solution may help you to get going with your problem

Assumptions
You want to pass the combo value before the second form get displayed
Form1_Combo_SelectionChange(sender,eventArgs)
{
  string selectedText = Convert.ToString(myCombo.SelectedItem);
  Form2 secondForm = Form2(selectedText);// while defining Form2 add a new Constructor with string as its parameter;
  secondForm.Show();//or ShowDialog()
}





如果你做的不同,请告诉我。



let me know if you are doing something different.


这篇关于如何获得Combobox价值......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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