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;
}
}
精彩评论