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

RadGridView Scrollbar Changes Cell Order

2 Answers 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
GM72
Top achievements
Rank 1
GM72 asked on 11 Sep 2012, 01:03 PM
Firstly, why can't I post this in the GridView forum?

I have the following:

Set AutoGenerateColumns = false;
Create the column bindings in the data_loading event handler

eg
GridViewDataControl dataControl = (GridViewDataControl)sender;

            dataControl.AutoGenerateColumns = false;
            dataControl.ShowGroupPanel = false;
            GridViewDataColumn column = new GridViewDataColumn();
            
            column.DataMemberBinding = new Binding("ID");
            column.Header = "PayPal ID";
            column.MaxWidth = 60;
            dataControl.Columns.Add(column);

..etc

This is fine and the columns show up as expected.

I also have a handler for RadGridView1_SelectionChanged

I use  
var selectedUIRow = RadGridView1.ItemContainerGenerator.ContainerFromItem(dataItem)
                    as Telerik.Windows.Controls.GridView.GridViewRow;
var firstCell = selectedUIRow.Cells[1] as Telerik.Windows.Controls.GridView.GridViewCell;

to capture the row and get a cell value. (I don't want to couple the row to an entity). This works fine.... Unless I move the scrollbar, then the cell order changes

This can't be right surely?

2 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 12 Sep 2012, 11:20 AM
Hello,

 You have such a problem because of the UI Virtualization and the fact that your are using GridViewCell (which is visual element) to get cell value. I would suggest you to work with the data objects instead of the visual elements. Please check the following approach:

private void radGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if ( e.AddedItems!=null && e.AddedItems.Count>0)
            {
                var selectedRow = e.AddedItems[0] as Employee;
                var firstCell = selectedUIRow.FirstName;
            }
       }
All the best,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
GM72
Top achievements
Rank 1
answered on 12 Sep 2012, 11:26 AM
Hi,

I'm not looking to couple my data objects to my UI unnecessarily.

I set the gird to a fixed length and removed the scrollbars to get round this
Tags
General Discussions
Asked by
GM72
Top achievements
Rank 1
Answers by
Yoan
Telerik team
GM72
Top achievements
Rank 1
Share this question
or