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

How to access rows and cells in RadGridView Which is already Loaded?

8 Answers 885 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jina
Top achievements
Rank 1
Jina asked on 01 Nov 2010, 03:35 AM
How to change background color of specific row, and foreground color of specific cell in RadGridView?

What i want to achieve is:
string name = 'Kim';
string location =  'JP';
 
for(int i = 0; i < grid.Rows.Count; i++)
{
   GridViewRow row = grid.Rows[i];
 
   if(row.Cells[0].Text == name)
   {
      row.BackGround = new SolidColorBrush(Colors.Orange);
 
      for(int j = 0; j < row.Cells.Count; j++)
      {
          if(row.Cell[j].Text == location)
          {
              row.Cells[j].FontWeight = FontWeights.Bold;
              row.Cells[j].Foreground = new SolidColorBrush(Colors.Blue);
          }
      }
   }
 
}

I can access rows and cells when grid_RowLoaded event occured.
also, i can access all rows in RadGridView like so:
Var rows = grid.ChildrenOfType<GridViewRow>();
foreach(GridViewRow row in rows)
{
    row = .... ;
}

but I can't access cells in each row.
--> row.Cells[0].... (X)


and,
I tried the following cord according to the manual
foreach(Object item in grid.Items)
{
  (item.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow).IsSelected = true;
}

but,
「this.item.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow」's value is always NULL.


Can you please help me how can I access  rows and cells in RadGridView Which is already Loaded?
thanks.

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 01 Nov 2010, 09:36 AM
Hi Jina,

The best possible approach here would be to use StyleSelectors for the cells and rows. You may take a look at our demos and online documentation for further reference.

Greetings,
Maya
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
Jina
Top achievements
Rank 1
answered on 02 Nov 2010, 06:45 AM
Thank you for your answer.

but,  I have a problem with StyleSelector.

The problem is StyleSelector is working only once when Data is loaded into RadGridView.

but,
I want to use StyleSelector not only when Data is loaded into RadGridView but also Data is already loaded into RadGridView.

I attach a file of example.

please check this out and please let me know how to solve it.
0
Maya
Telerik team
answered on 02 Nov 2010, 09:46 AM
Hi Jina,

We did have a similar issue where the StyleSelectors are not invoked on changing the data, but it has already been fixed. So, I would ask you to try out with either our latest release or with an internal build.
In case it does not resolve the problem, I would need more details about the expected behavior. Do you require the color of the row of the selected item to be changed according to the selected item in the first row ?

Sincerely yours,
Maya
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
Jina
Top achievements
Rank 1
answered on 04 Nov 2010, 04:29 AM
Hi Maya,

Thank you for your reply.

Is this a similar issue you metioned?
http://www.telerik.com/community/forums/silverlight/gridview/cellstyleselector-when-changing-the-value-the-styleselector-is-not-called.aspx

is there no solution outside RadGridView.Rebind()?
I am looking for  a solution that is not RadGridView.Rebind().
while the RadGridView loop from first row to last row in RadGridView,
l want to access all data in GridView, and I want to find out the rows and cells what i want to edit style.


also,
I have tried Dan Kane's Code, but it doesn't work.
----------------------------------------------------------------------------------------------------------------------------------------------------
foreach(var item in ParametersGridView.Items)
{
var row  = ParametersGridView.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;
.
.
.
}
----------------------------------------------------------------------------------------------------------------------------------------------------
'row' value is always NULL.
I think this code is very useful.
but I cannot use it because 'row' value is always NULL.
please teach me, why row is  always Null?
0
Accepted
Maya
Telerik team
answered on 04 Nov 2010, 10:09 AM
Hello Jina,

Did you test your application with the binaries from our Latest Internal Build ? Furthermore, do you require the color of the row of the selected item to be changed according to the selected item in the first row ? Please specify more details because so far I am not able to provide you with any solution unless I have more information about your requirements. 
Considering the case where the rows are "null", it depends on the time you are expecting to get and work with them. The reason for them to be "null" may be that they have not yet been loaded.
 

Sincerely yours,
Maya
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
Jaime Bula
Top achievements
Rank 2
answered on 04 Oct 2012, 04:28 PM
In my scenario, I need to set the color by reading the previous row.

Is there a way to access the cells? Using selectors is an overkill on this simple scenario.

Best Regards.

0
Mike
Top achievements
Rank 1
answered on 31 Dec 2012, 05:34 PM
I've the same problem. Is there a simpler solution without using complex selectors for just changing the color?
0
Maya
Telerik team
answered on 02 Jan 2013, 07:48 AM
Hello Mike,

If you want just to change a color, then you can easily define a style for the element you want. Otherwise, if you require to change that color based on some custom logic - like the values in the cell for example - then you will need a bit more complex solution (as using style selectors). Do you have any troubles with the implementation ?  

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Jina
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jina
Top achievements
Rank 1
Jaime Bula
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or