所以我有一个winform,其中我有一个包含信息的数据网格,我想在其中搜索但是我希望搜索的标准是产品的年份(int)及其类型(字符串)。
products[] a = new products[productscopy.Count];
int type = int.Parse(textBox2.Text);
int year = int.Parse(textBox1.Text);
int br = 0;
foreach (products sl in productscopy)
{
if (sl.Year == year && sl.Type == type) //line that causes problem
{
a[br] = sl; br++;
}
}
if (br > 0)
{
products[] b = new products[br];
for (int i = 0; i < br; i++)
{
b[i] = a[i];
}
dataGridView1.DataSource = b;
dataGridView1[0, 0].Selected = false;
}
else { dataGridView1.DataSource = null; }