开发者

How to get the text from a selected row on Winforms DataGrid?

This seems like it would be easy but I can't find a way开发者_开发知识库 to retrieve the text from the selected row on a DataGrid. The grid is single row selected only - no multiple row selection is allowed.


Figured it out. One way is

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


This is how you get the text of the entire row (as opposed to the existing answer that shows how to get a single value from a DataGrid):

string str = "";
int row = datagrid.CurrentRowIndex;
int col = 0;
while (true)
{
    try
    {
        str += datagrid[row,col].ToString() + "|";
        col++;
    }
    catch
    {
        break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜