0

这似乎很容易,但我找不到从 DataGrid 上的选定行中检索文本的方法。网格仅选择单行 - 不允许选择多行。

4

2 回答 2

3

Figured it out. One way is

string val = (string)dataGrid1[1, 1]; // cell 1, row 1

于 2010-04-15T15:38:07.767 回答
0

这是您获取整行文本的方式(与显示如何从 DataGrid 获取单个值的现有答案相反):

string str = "";
int row = datagrid.CurrentRowIndex;
int col = 0;
while (true)
{
    try
    {
        str += datagrid[row,col].ToString() + "|";
        col++;
    }
    catch
    {
        break;
    }
}
于 2016-03-04T07:49:02.367 回答