How to get GridViewCell from GridViewCellInfo

9 posts, 0 answers
  1. Ivano
    Ivano avatar
    39 posts
    Member since:
    Feb 2009

    Posted 30 Jun 2010 Link to this post

    Hi

    I need to apply same formatting to selected cells; something like this:

                foreach (GridViewCellInfo cellInfo in gridView.SelectedCells)
                {
                    GridViewCell cell=??;
                    switch (action)
                    {
                        case "Size":
                            cell.FontSize = 12.0;
                            break;
                        .......
                    }
                }

    how can I get the GridViewCell from GridViewCellInfo in Q2 2010 version?

    Thanks
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Jun 2010 Link to this post

    Hi Ivano,

    Here is no easy conversion from GridViewCellInfo into GridViewCell. One of the problems with this is that you can never get all GridViewCells because RadGridView uses virtualization and only a portion of all cells are available.

    You could take a look at this blog post which demonstrates how you can implement conditional formatting using behaviors or alternatively you could try using Style/Template selectors as demonstrated here.


    Best wishes,
    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
  3. Ivano
    Ivano avatar
    39 posts
    Member since:
    Feb 2009

    Posted 01 Jul 2010 Link to this post

    Hi
     
    A property like "gridViewCellInfo.GridViewCell" could very usefull to enable fine grain formatting on selected cells while a "IsValid" property could let you know where the row has been loaded.
    Consider that Microsoft basic DataGrid (.Net 4.0) let you get DataGridCell from DataGridCellInfo and the control implements rows and columns virtualization too.
    I hope RadGridView will support at least all Microsoft basic DataGrid features.

    Sincerely
    Ivano.
  4. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 01 Jul 2010 Link to this post

    Hi Ivano,

    We will consider introducing such additions to RadGridView. Thank you for your feedback.


    Kind regards,
    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
  5. Ivano
    Ivano avatar
    39 posts
    Member since:
    Feb 2009

    Posted 02 Jul 2010 Link to this post

    Hi

    the blog post or Style/Template selectors do not solve my problem; is there any other way to get GridViewCell from Column and Item properties?

    Sincerely
  6. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 06 Jul 2010 Link to this post

    Hello Ivano,

    You could try the following:

    GridViewCellInfo cellInfo;
    var row = this.corrGrid.ItemContainerGenerator.ContainerFromItem(cellInfo.Item) as GridViewRow;
      
    foreach (GridViewCell cell in row.Cells)
    {
        if (cell.Column == cellInfo.Column)
        {
            // cell found
        }
    }


    Kind regards,
    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
  7. Ivano
    Ivano avatar
    39 posts
    Member since:
    Feb 2009

    Posted 06 Jul 2010 Link to this post

    Hi

    your suggestion works fine.

    Thanks.

  8. Pieter Jan Verfaillie
    Pieter Jan Verfaillie avatar
    11 posts
    Member since:
    Dec 2009

    Posted 14 Dec 2012 Link to this post

    Hi, 


    I've found this post really helpfull, but I'm having some problems. It seems that if the selected cell isn't visible (by which I mean that the columns are scrolled out of the visible part of the grid), the row of the selected cell isn't found. The row is null.

    foreach (var selectedCell in grid.SelectedCells)
        {
            var row = grid.ItemContainerGenerator.ContainerFromItem(selectedCell.Item) as GridViewRow;
            if (row == null) continue;
     
    ...

    I suppose this has something to do with the virtualization of the grid. 
    Is there a way to get the row, even when the cell is outside the visible part?

    Kind regards, 
    Pieter Jan
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Dec 2012 Link to this post

    Hello,

    Since the virtualization of the GridView is turned on by default, it is not recommended to work with the visual elements (i.e. GridViewRow) and their properties. When a row is out of view, it actually does not exist. Please check this help article for a reference.

    You could get the data object bound to the parent row with a code similar to yours and then work with the boundItem:

    Club boundItem = this.clubsGrid.SelectedCells[0].Item as Club;

    I hope this helps.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top