dataGridView一列去重,放到集合中循环调出

 dataGridView一列去重,放到集合中循环调出,我是去重的第二列,所以Cells[1]为1,要填写这个数字的时候记得看看你自己有几列,别没有这个列,缺多写了,导致索引报错。集合记得要用泛型llist。为什么?看下面

Contains:确定 某元素是否存在System.Collections.Gentric.List<T>

dataGridView一列去重,放到集合中循环调出

 

 

List<string> lsName = new List<string>();

public void deleterepaet()
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                string name = this.dataGridView1.Rows[i].Cells[1].Value.ToString();//找到自己需要对比的那一列
                if (lsName.Contains(name))//如果一样返回for循环继续执行
                {
                    continue;
                }
                else
                {
                    lsName.Add(name);
                }
            }
            for (int j = 0; j<lsName.Count; j++)
            {
                WebRefeSap.ZmmfmBarcodeGetResponse response = webRefeSapZmmfmBarcodeGet(lsName[j]);
             //   MessageBox.Show("lsName[" + j + "]====" + lsName[j]);
            }
        }