Click to See Complete Forum and Search --> : help


knz
July 31st, 2002, 01:40 PM
Hi,
I have a datagrid control having 3 columns.
Also in my form I have 3 separate textboxes.
And OnClick of a button I want the values from
a selected record(or row) from the datagrid to
be displayed in the 3 textboxes(ie each column
value in a textbox)
Can this be done?

dvlpr
July 31st, 2002, 02:47 PM
Yes....
That's the simple answer. One way to do it...

int selectedRow = dataGridOfStuff.CurrentRowIndex;
DataGridCell currCell = new DataGridCell();
// look at the different column values in the row
currCell.RowNumber = currRow;
currCell.ColumnNumber = 0;
string value0 = dataGridEmployees[currCell].ToString().Trim() ;
currCell.ColumnNumber = 1;
string value1 = dataGridEmployees[currCell].ToString().Trim() ;
currCell.ColumnNumber = 2;
string value2 = dataGridEmployees[currCell].ToString().Trim() ;


That will get you the values at least. There is probably a better way, but it will get you started playing around with it. And don't forget your try/catch blocks. You could also put this in the double-click event for the datagrid. That way you can still resize and sort the columns.

Hope it helps.

dvlpr
July 31st, 2002, 02:49 PM
The line

currCell.RowNumber = currRow;

should have read

currCell.RowNumber = selectedRow;

sorry