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
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.
Maya
the Telerik team
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.
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 ?
Maya
the Telerik team
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?
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.
Maya
the Telerik team
Is there a way to access the cells? Using selectors is an overkill on this simple scenario.
Best Regards.
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.