我试图只显示DataGridView
输入的姓氏的行。从那里我可以构建我的程序的其余部分,但我遇到了减速带。我在网上看到了我的活动中的那段代码,但它不起作用。它在 else 括号处中断。有什么建议吗?对不起,我是新手,但如果我学过一次,我会永远记住。Submit_Button_Click
public partial class Form1 : Form
{
string LastName;
//string FirstName;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.aRMORERS_TableAdapter.Fill(this.armorersDataSet._ARMORERS_);
}
private void Submit_Button_Click(object sender, EventArgs e)
{
LastName = LastName_TextBox.Text;
//FirstName = FirstName_TextBox.Text;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value.ToString() == LastName)
{
dataGridView1.Rows[i].Selected = true;
dataGridView1.Rows[i].Visible = true;
}
else
{
dataGridView1.Rows[i].Visible = false;
dataGridView1.Rows[i].Selected = false;
}
}
}
}