如果C#winform遇到卡地亚,则从1列复制到另一列 [英] C# winform copy from 1 column to another column if it meets a cartier

查看:61
本文介绍了如果C#winform遇到卡地亚,则从1列复制到另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导入网格的文件,如果它遇到卡地亚到另一列,我想复制A列中的数据。例如:如果列D具有Yeshh,则将列A复制到列C.我有部分工作,最后2行我遇到麻烦,如果它遇到不同的卡地亚返回该列中的内容。

以下编码显示在单元格DataGridViewTextBoxCell {ColumnIndex = 13,RowIndex = 0}而不是结果。







I have a file I import into a grid, I want to copy the data from A column if it meets the Cartier to another column. example: if column D has "Yeshh" copy column A into column C. I have part of it working, the last 2 line I have trouble if it meets a different cartier return what is in that column.
the below coded show this in the cell DataGridViewTextBoxCell { ColumnIndex=13, RowIndex=0 } instead of the results.



<pre>private void btn_Adjust_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow rows in dataGridView1.Rows)
            {
                for (int i = 0; i < dataGridView1.RowCount - 1; i++)
                {
                    if (dataGridView1.Rows[i].Cells[24].Value.ToString() == "Yesmix")
                    {
                        dataGridView1.Rows[i].Cells[17].Value = "48";
                    }

                    else
                    {
                        if (dataGridView1.Rows[i].Cells[24].Value.ToString() == "Yeshh")     // this not working
                        {
                           dataGridView1.Rows[i].Cells[17].Value = dataGridView1.Rows[i].Cells[13];      // this not working
                        }
                    }
                }
            }
        }





我尝试过:





What I have tried:

DataGridViewTextBoxCell { ColumnIndex=13, RowIndex=0 }

推荐答案

I已找到解决方案。











I have found a solution.





<pre>private void btn_Adjust_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow rows in dataGridView1.Rows)
            {
                for (int i = 0; i < dataGridView1.RowCount ; i++)
                {
                    if (dataGridView1.Rows[i].Cells[24].Value.ToString() == "Yesmix")
                    {
                        dataGridView1.Rows[i].Cells[17].Value = "48";
                        dataGridView1.Rows[i].Cells[16].Value = "45";
                    }

                    else
                    {
                           if (dataGridView1.Rows[i].Cells[24].Value.ToString() == "Yeshh")
                        {
                            var value1 = dataGridView1.Rows[i].Cells[13].Value.ToString();
                            dataGridView1.Rows[i].Cells[17].Value = value1;

                            var value2 = dataGridView1.Rows[i].Cells[12].Value.ToString();
                            dataGridView1.Rows[i].Cells[16].Value = value2;

                            var value3 = dataGridView1.Rows[i].Cells[14].Value.ToString();
                            dataGridView1.Rows[i].Cells[18].Value = value3;


                        }


这篇关于如果C#winform遇到卡地亚,则从1列复制到另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆