C#在文本框中插入数据并在组合框中显示该数据 [英] C# to insert data in textbox and to display that data in combobox

查看:118
本文介绍了C#在文本框中插入数据并在组合框中显示该数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有两种形式.在一种形式(form1)中,我有一个文本框可以从用户那里获取名称..我希望获得相同的名称,以便在另一种form(form2)组合框中显示物品.我该怎么做?我正在使用Access作为数据库.

I have two forms in c#.. in 1 form(form1) i have a text box to get name from user..i wish to get the same name to be displayed in another forms(form2) combo box''s item. how do i do it? i am using Access as database.

推荐答案

据我所知,除非您要将信息存储在数据库中并在另一个数据库中检索它,否则Access是无关紧要的.表格-这不是最明显或最有效的方法!

您要在第二个表单上创建一个属性以接受名称:
As far as I know, Access is irrelevant unless you are going to store the info in a database and retrieve it in a different form - which is not the most obvious or efficient way to do it!

You want to create a property on the second form to accept the name:
public string UserName { get; set; }


然后在显示来自Form1的Form2之前设置值:


Then set the value before you display the Form2 from Form1:

Form2 f2 = new Form2();
f2.UserName = myTextBox.Text;
f2.ShowDialog();

在UserName属性的setter中,可以设置ComboBox值-并使用getter来检索当前选定的项目.

In the setter of the UserName Property, you can set the ComboBox value - and use the getter to retrieve the currently selected item.


这篇关于C#在文本框中插入数据并在组合框中显示该数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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