繁体   English   中英

C# Winforms如何基于同一行上的另一个单元格从Datagridview获取文本到label?

[英]C# Winforms how to get text from Datagridview to a label based on another cell on the same row?

我正在寻找以下问题的答案:

这是我的 DataGridView: DataGridView

导入的数据每 5 分钟更新一次,这会更改行数和顺序。 如何根据同一行上的另一个单元格获取一个单元格的数据?

例如,在图片中,我想让“raw_text”单元格显示在 label 上。 要获得正确的单元格,我需要检查“station_id”是否为“AGGH”,然后将该行中的所有信息获取到不同的标签。

我试过这个:

labelmetar.Text = dataGridView1.Rows[1].Cells["raw_text"].Value as string;

但是行一直在变化,所以这是不可能的。 而不是行号( .Rows[1] ...),它应该询问“station_id 等于 AGGH 的行”。 我怎样才能做到这一点?

有什么建议吗? 非常感谢!

            foreach (DataGridViewRow dgvRow in dataGridView1.Rows)
            {
                if (dgvRow.Cells["station_id"].Value.ToString() == "AGGH")
                {
                    string rawText = dgvRow.Cells["raw_text"].Value.ToString();
                }
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM