This is a migrated thread and some comments may be shown as answers.

Get Selected Row Fails When Using Drag-n-Drop GroupBy

2 Answers 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael Semanson
Top achievements
Rank 1
Michael Semanson asked on 12 Mar 2010, 10:57 PM
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

2 Answers, 1 is accepted

Sort by
0
Michael Semanson
Top achievements
Rank 1
answered on 16 Mar 2010, 12:22 PM
Is anyone from Telerik looking at this?
0
Milan
Telerik team
answered on 16 Mar 2010, 03:36 PM
Hello Michael Semanson,

Currently this is expected since ItemsContainerGenerator cannot return row containers when RadGridView is grouped. but you could take another approach. Instead of using the UI elements to get the data you can get the needed data from the data items themselves. 

var selectedItem = e.AddedItems[0];
// cast the selected item to the expected data item type 
var selectedDataItem = (MyDataType)selectedItem;
// once we have casted to the expected type we can extract the needed property values
var neededPropertyValue = selectedDataItem.MasterID;

Hope this helps.

All the best,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Michael Semanson
Top achievements
Rank 1
Answers by
Michael Semanson
Top achievements
Rank 1
Milan
Telerik team
Share this question
or