【发布时间】:2014-11-19 16:28:48
【问题描述】:
单击“添加”按钮时,我正在使用此代码将用户输入添加到我的数组中。
int newcompartment;
string newproductcode, newname, newaddress;
float newweight;
newcompartment = int.Parse(txtcompartment.Text);
newproductcode = txtproduct.Text;
newname = txtname.Text;
newaddress = txtaddress.Text;
newweight = float.Parse(txtqty.Text);
if ((newcompartment > 0) && (newcompartment < productcode.Length) && (rbtnoccupied.Checked == true))
{
if (productcode[newcompartment - 1] != "")
{
MessageBox.Show("Compartment is occupied !");
}
else
{
MessageBox.Show("You have successfully added a new array data!");
compartmentno[newcompartment - 1] = newcompartment;
productcode[newcompartment - 1] = newproductcode;
name[newcompartment - 1] = newname;
weight[newcompartment - 1] = newweight;
address[newcompartment - 1] = newaddress;
}
}
我想知道是否有可能有一个 "MODIFY" 按钮,用户可以在其中输入新的输入来替换数组中以前添加的部分或全部数据?
以防万一,如果需要,我的 GUI 包含 5 个文本框和 2 个单选按钮(compartment no、product code、name、weight、address)和(Occupied /Empty )。
【问题讨论】:
-
你想要一个可以输入文本的按钮吗?
-
您的问题到底是什么?你想获得一个索引来修改你的数组数据吗?
-
如果您使用 List
而不是字符串数组,您可以使用它的 .Add 方法向其中添加项目。 -
我想让用户在文本框和单选按钮中输入他们的数据,当点击“修改”按钮时,输入的新数据将替换旧的数组数据。