如何将DataGridView某一列的所有值循环添加到string[],然后用foreach语句循环遍历。

解决方案 »

  1.   

    string[] strs = new string[dataGridView.Rows.Count];
                int i=0;
                foreach(DataGridViewRow row in dataGridView.Rows)
                {
                    strs[i++] = row.Cells[列索引].FormattedValue.ToString();
                }            foreach (string str in strs)
                {            }
      

  2.   

    简单说一下思路,首先你定义一个数组,然后你循环遍历  datagridview中的items  动作时增加到 你刚才所定义的数组中~~不知道可以帮到你么 ?