Using the following Event Handler for RadGrid SelectionChanged, I have been able to successfully extract a value from the selected row and pass it through as a parameter to a stored procedure when the grid is in a normal (non groupby) situation.
However, as soon as a a column header is drag-n-dropped into the GroupBy region of the grid, the function is unable to properly extract the needed value.
private void radASNMaster_SelectionChanged(object sender, SelectionChangeEventArgs e) |
{ |
bool columnFound = false; |
try |
{ |
radDetailsView.IsBusy = true; |
// Get the selected row so we can extract the AsnInMasterID value and pass it into the Stored Procedure |
var selectedRow = e.AddedItems[0]; |
var selectedUIRow = radASNMaster.ItemContainerGenerator.ContainerFromItem(selectedRow) as Telerik.Windows.Controls.GridView.GridViewRow; |
// Columns could have been reordered by user so we need to step through available columns and look for AsnInMasterID. |
for (int columnIndex = 0; (columnIndex < selectedUIRow.Cells.Count) && !columnFound; columnIndex++) |
{ |
var asnMasterIDCell = selectedUIRow.Cells[columnIndex] as Telerik.Windows.Controls.GridView.GridViewCell; |
if (asnMasterIDCell.Column.Header.ToString() == "AsnInMasterID") |
{ |
// We found our column. Extract the AsnInMasterID value and pass it into the stored procedure. |
var proxy = new CACrossDockSvc.CACrossDockServiceClient(); |
proxy.GetASNDetailsByMasterIDCompleted += new EventHandler<CAXDock.CACrossDockSvc.GetASNDetailsByMasterIDCompletedEventArgs>(proxy_GetASNDetailsByMasterIDCompleted); |
proxy.GetASNDetailsByMasterIDAsync(Convert.ToInt32(asnMasterIDCell.Value.ToString())); |
columnFound = true; |
} |
} |
if (!columnFound) |
throw new Exception("ColumnNotFound"); |
} |
catch |
{ |
radDetailsView.ItemsSource = null; |
radDetailsView.IsBusy = false; |
} |
} |
Specifically, when the grid is GroupedBy any column and the user selects a row, the above function executes but the line
"var selectedUIRow = radASNMaster.ItemContainerGenerator.ContainerFromItem(selectedRow) as Telerik.Windows.Controls.GridView.GridViewRow;" returns null for selectedUIRow. Obviously, the rest of the function fails to work properly because of the null value.
One last piece of information I can provide is that I recently (today) upgrade the Telerik Silverlight controls to Q1 2010 from Q3 2009, and I'm pretty sure this worked properly with the older release.
What do I need to do to get this to work?
Thank you,
Michael