gpt4 book ai didi

c# - 如何将数组值添加到组合框中?

转载 作者:行者123 更新时间:2023-11-30 19:10:18 25 4
gpt4 key购买 nike

我已将变量定义为 string 数组。我还有一个名为 form4 的表单,在这个表单上我有 1 个文本框和 1 个组合框。

我在类里面有这段代码:

public class food
{
public string[] name1 = new string [20];
public string[] name2 = new string [50];
public string[] name3 = new string [40] ;
public string[] name = new string [20];
public string[] type = new string [15];
//private const int total = 11;
public int[] calories_ref;
public int i, i2;
public Form4 form = new Form4();


public food(string[] Name1, string[] Name, string[] Type1, int[] kcal)
{
name1 = Name1;
name = Name;
type = Type1;
calories_ref = kcal;
}
public food()
{

}
private void settypes()
{

type[0] = "Bebidas não alcoólicas";
type[1] = "Bebidas Alcóolicas";
type[2] = "Fruta";
type[3] = "Hidratos de Carbono";
type[4] = "Peixe";
type[5] = "Carne";
type[6] = "Cereais";
type[7] = "Lacticínios";
type[8] = "Óleos/Gorduras";
type[9] = "Leguminosas";
type[10] = "Legumes";

for (int i = 0; i < type.Length; i++)
{
form.comboBox1.Items.Add(type[i]);
}
}

settypes() 方法中,我定义了各种类型的食物,更具体地说是食物轮。如何将这些值用作 form4 中组合框中的项目?

最佳答案

您可以使用 comboBox 中的方法 AddRange(array[]) 添加一个字符串数组。

form.comboBox1.Items.AddRange(type);

关于c# - 如何将数组值添加到组合框中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18543299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com