日期:2014-05-17  浏览次数:21037 次

判断datagridview某列是否含有某字段
现在想循环遍历一个datagridview,判断其某列的值中是否含有“辊道”两字,如果有且其数量《15,则开关箱尺寸为600*400*1200,数量>15开关型尺寸为800*400*1200
datagridview遍历 单元格含有某字段

------解决方案--------------------
DataTable dt = new DataTable();
            dt.Columns.Add("M_name", typeof(string));
            dt.Columns.Add("M_number", typeof(string));
            dt.Columns.Add("开关箱尺寸", typeof(string));

            dt.Rows.Add("滚到", "12", "");
            dt.Rows.Add("送辊", "1", "");
            dt.Rows.Add("滚辊道到", "162", "");

            this.dataGridView1.DataSource = dt;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                DataGridViewRow g = this.dataGridView1.Rows[i];
                if (g.Cells["M_name"].Value != null && g.Cells["M_name"].Value.ToString().Contains("辊道"))
                {
                    if (g.Cells["M_number"].Value != null)
                    {
                        if (Convert.ToInt32(g.Cells["M_number"].Value) > 15)
                        {
                            g.Cells["开关箱尺寸"].Value = "800*400*1200";
                        }
                        else
                        {
                &nb