【发布时间】:2016-01-11 00:15:19
【问题描述】:
所以我在这里是我的代码:我有 2 种形式, - form1 中的按钮将您带到 form2 。 -form2 里面有Datagridview - 在表格 1 中输入信息(姓名、年龄),然后将它们加载到表格 2 的数据网格视图中 - 当我选择一行来删除数据网格视图时,我希望该行也从数组中删除。(我该怎么做) 提前谢谢你
class Class1
{
public struct client
{
public string nom;
public string prenom;
public int age;
}
public static client[] TC = new client[100];
public static int i = 0;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
private void btn_ajouter_Click(object sender, EventArgs e)
{
Class1.TC[Class1.i].nom = textBox_nom.Text;
Class1.TC[Class1.i].prenom = textBox_prenom.Text;
Class1.TC[Class1.i].age = int.Parse(textBox_age.Text);
textBox_age.Clear();
textBox_nom.Clear();
textBox_prenom.Clear();
Class1.i = Class1.i + 1;
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void btn_afficher_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
for (int j = 0; j <= Class1.i-1; j++)
{
dataGridView1.Rows.Add(Class1.TC[j].nom,Class1.TC[j].prenom,Class1.TC[j].age);
}
}
private void btn_supprimer_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
}
}
【问题讨论】:
-
你有什么问题?你到底卡在哪里了?您如何尝试从数组中删除元素? (提出的重复问题对此有一些很好的解决方案。)