Greetings,
We're starting to transition our legacy C# apps from earlier versions to
VS2008 versions.
Many of our apps allow the user to select a row from a DataGrid into a 'Data
Edit' area composed of Text, Combo, etc boxes that contain the individual
columns of the DataGrid row.
To extract information from the user selected DataGrid row we use the
following code ....
Given a DataGrid / DataGridView named "dgResults"
string sSelectedDirID = null;
string sSelectedGridID = null;
DataRowView oDrvSelectedGridRow = null;
try
{
oDrvSelectedGridRow =
(DataRowView)this.BindingContext[dgResults.DataSource,
dgResults.DataMember].Current;
sSelectedDirID = oDrvSelectedGridRow["Dir_id"].ToString().Trim();
sSelectedGridID = oDrvSelectedGridRow["Grid_id"].ToString().Trim();
}
catch { return;}
The best translation of the code above for a DataGridView seems to be
something like
string sSelectedDirID = null;
string sSelectedGridID = null;
DataRowView oDrvSelectedGridRow = null;
try
{
oDrvSelectedGridRow = this.dgResults.CurrentRow.DataBoundItem AS
DataRowView;
sSelectedDirID = oDrvSelectedGridRow["Dir_id"].ToString().Trim();
sSelectedGridID = oDrvSelectedGridRow["Grid_id"].ToString().Trim();
}
catch { return;}
Anyone have a better approach ?
Thanks in advance.
Barry in Oregon.