如何将comboBox数据源从form1链接到form2 comboBox?

编程入门 行业动态 更新时间:2024-10-28 01:25:06
本文介绍了如何将comboBox数据源从form1链接到form2 comboBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何显示来自form1 comboBox的form2中comboBox中的成员?

how can I display members in comboBox in form2 from form1 comboBox?

Form form1 = Application.OpenForms["Form1"]; private void BookSetupForm_Load(object sender, EventArgs e) { comboBox1.DataSource = form1boBox1; }

问题有所不同,因为我想传输comboBox值而不是文本框值和用法

The question is different as I want to transfer comboBox values not textboxes values and uses a different approach.

推荐答案

因为表格1上的 ComboBox 是不是 public ,您需要一个额外的字段或属性作为传输对象:

Since the ComboBox on your Form 1 is not public you would need an extra field or property as transfer object:

public partial class Form1 : Form { public ComboBox comboTransfer; public Form1() { InitializeComponent(); // example combobox thisboBox1.Items.AddRange(new string[] { "1", "2", "3" }); // reroute the content thisboTransfer = comboBox1; } }

在表格2中,您可以访问该转移对象

In Form 2 you could access then this transfer object

public partial class Form2 : Form { Form1 Form_1; public Form2() { InitializeComponent(); Form_1 = Application.OpenForms["Form1"] as Form1; } private void BookSetupForm_Load(object sender, EventArgs e) { // access here your transfer object thisboBox1.DataSource = Form_1boTransfer.Items; } }

这只是这样做的一种方法(首先在我脑海中浮现)

this is just one way of doing it (first that came to my mind)

更多推荐

如何将comboBox数据源从form1链接到form2 comboBox?

本文发布于:2023-11-12 23:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   如何将   链接   comboBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!