如何获取datagridview选中的单元格值(文本) [英] how to get the datagridview selected cell value(text)

查看:580
本文介绍了如何获取datagridview选中的单元格值(文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人帮我获取datagridview选择的单元格值(文本)而不使用row.cell [index]



(或)



点击datagridview单元格我们必须找到它的绑定字段或模板字段

Any one help me to get the datagridview selected cell value(text) without using the row.cell[index]

(or)

by click the datagridview cell we have to find its a bound field or template field

推荐答案

DataGridView.SelectedCells is a collection of cells, so it's not as simple as calling ToString() on it. You have to loop through each cell in the collection and get each cell's value instead.

The following will create a comma-delimited list of all selected cells' values.










TextBox1.Text = "";
bool FirstValue = true;
foreach(DataGridViewCell cell in DataGridView1.SelectedCells)
{
    if(!FirstValue)
    {
        TextBox1.Text += ", ";
    }
    TextBox1.Text += cell.Value.ToString();
    FirstValue = false;
}









DataGridView.SelectedCells [ ^ ]


这篇关于如何获取datagridview选中的单元格值(文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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