RadGridView Scrollbar Changes Cell Order

3 posts, 0 answers
  1. GM72
    GM72 avatar
    23 posts
    Member since:
    Sep 2012

    Posted 11 Sep 2012 Link to this post

    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

    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;


    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. Yoan
    Yoan avatar
    1213 posts

    Posted 12 Sep 2012 Link to this post


     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,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. GM72
    GM72 avatar
    23 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post


    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
Back to Top