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

How to get GridViewCell from GridViewCellInfo

8 Answers 1196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ivano
Top achievements
Rank 1
Ivano asked on 30 Jun 2010, 07:54 PM
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

8 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 30 Jun 2010, 08:00 PM
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
0
Ivano
Top achievements
Rank 1
answered on 01 Jul 2010, 09:02 AM
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.
0
Milan
Telerik team
answered on 01 Jul 2010, 09:08 AM
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
0
Ivano
Top achievements
Rank 1
answered on 02 Jul 2010, 02:59 PM
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
0
Milan
Telerik team
answered on 06 Jul 2010, 08:24 AM
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
0
Ivano
Top achievements
Rank 1
answered on 06 Jul 2010, 09:24 AM
Hi

your suggestion works fine.

Thanks.

0
Pieter Jan Verfaillie
Top achievements
Rank 1
answered on 14 Dec 2012, 03:54 PM
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
0
Dimitrina
Telerik team
answered on 15 Dec 2012, 09:36 AM
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.

Tags
GridView
Asked by
Ivano
Top achievements
Rank 1
Answers by
Milan
Telerik team
Ivano
Top achievements
Rank 1
Pieter Jan Verfaillie
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or