I'm using a RadTreeListView (SL v5).
In a Converter (an object that implements IValueConverter), I'm doing something like this:
Unfortunately, this code doesn't work since the DisplayIndex seems to be relative.
How is it possible to have the real index of the column ?
7 Answers, 1 is accepted
You could find the index of the particular column in the GridView.Columns collection and use it instead of the DisplayIndex.
I hope that this is what you need.
the Telerik team
Thanks for your fast answer.
This partially solved my problem. I modified my code like this:
int index = cell.ParentRow.GridViewDataControl.Columns.IndexOf(cell.Column) - cell.ParentRow.GridViewDataControl.FrozenColumnCount;
and now I've got the correct index !
But now the problem is that my Converter is not always called, and I suspect that virtualization is the problem, because setting EnableColumnVirtualization="False" on my RadTreeListView solve this problem (but it's unfortunately not usable anymore because without virtualization it's too slow...).
This is my XAML:
And the assignment:
I hope you can help.
The reason for this problem seems to be that you work with the visual elements (i.e. cell) to set the CellStyleSelector of the corresponding column.
Generally it is not a good practice to work with the visual elements of the grid. As you know, when the row virtualization is set to True, then the rows (cells) are reused. You may find more information about virtualization in this help article.
I am not sure how you apply the converter and what is your logic, but you would better change it so that you do not rely on the visual elements.
the Telerik team
No, I'm not using a visual element to set the CellStyleSelector.
To see what I want to achieve, have a look at the attached image.
As you can see, I've got a time period, each column representing a week.
Then, I'm drawing 'Tasks', basically it's the colored rectangle you can see on the image. Each task is surrounded by a border. The border is composed of four pieces (left, middle, right and all (all is useful when a task is just one week)).
The user can set a period, for example, in the image, from week 26 to week 38. But it could happen that a task is longer than the time period defined by the user. In this case, I want to display a dotted border, like on the image (week 26) to show that it's not the end.
For this, I did the following:
1) In XAML, specify the four types of border (you can find a sample of the XAML in the second message of this thread, it represents the 'middle' border).
2) Use a Selector (a class that extends StyleSelector) to select which border I have to display (I've got some logic there...)
3) Finally, add some customizations (the color of the 'Task', the style of the border (dotted, dashed), etc.) depending on some criteria’s. I'm using a Converter (a class that implements IValueConverter) to do this.
As you can see in my XAML, I set the converter of the border like this:
This gives me a chance, in the converter, to retrieve the underlying Task object (DataContext).
Unfortunately, due to virtualization, the converter is not always called. Disabling the virtualization solves the problem, but then it becomes so slow that it's not usable anymore.
I hope that now my problem is clearer...
If you have an idea how I can solve this, I would appreciate that you share it :-)
It's definitively not possible to solve the problem like this, since everything is virtualized…
I found another way to fix the problem...
It is good to hear that you have solved the problem. Would you share with us what is the other way to do this? Is it what you need, or you have any doubts on it?
the Telerik team
Without going to much into details, I did the following:
1) I added a new dotted Style in my XAML
2) I selected the style in a style selector (a class that extends StyleSelector)
3) I set ONLY the background color with a Converter (and not the style).
The trick here is to use the Converter for the background color. It works because the background color is always the same for a task and thus it doesn't have the problem of grid virtualization (which is not the case for the border which is sometimes dotted/dashed/... for the same task).