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

DisplayIndex

7 Answers 117 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AKROS
Top achievements
Rank 1
AKROS asked on 29 Dec 2011, 05:22 PM
Hi Telerik Team,

I'm using a RadTreeListView (SL v5).
In a Converter (an object that implements IValueConverter), I'm doing something like this:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
   Brush brush = null;
 
   if(value is GridViewCell)
   {
      GridViewCell cell = (GridViewCell)value;
      Task task = cell.DataContext as Task;
 
      if(task != null)
      {
         int index = cell.Column.DisplayIndex - cell.ParentRow.GridViewDataControl.FrozenColumnCount;
         // Check if we are left or right
         if((index == 0 && task.MissingToLeft > 0) || (index == task.NormalizedWeeklyTasks.Count - 1 && task.MissingToRight > 0))
         {
            // ...
         }
      }
   }
   return brush;
}


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 ?

Greetings,
Nicolas

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Dec 2011, 09:59 AM
Hello Nicolas,

 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. 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
AKROS
Top achievements
Rank 1
answered on 30 Dec 2011, 11:25 AM
Hi Didie,

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:
selectors:PlanningCellStyleSelector x:Key="tvCellStyleSelector">
<selectors:PlanningCellStyleSelector.MiddleStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="telerik:GridViewCell">
<Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=telerik:GridViewCell}, Converter={StaticResource planningBorderConverter}}" BorderThickness="0,2,0,2">
<Canvas Background="{Binding Converter={StaticResource planningCanvasConverter}}">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="Stretch"/>
</Canvas>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0,0,1,1"/>
</Style>
</selectors:PlanningCellStyleSelector.MiddleStyle>
<!-- ... -->
</selectors:PlanningCellStyleSelector>

And the assignment:
GridViewDataColumn column = new GridViewDataColumn();
column.CellStyleSelector = this.Resources["tvCellStyleSelector"] as StyleSelector;

I hope you can help.
Best Regards,

Nicolas
0
Dimitrina
Telerik team
answered on 30 Dec 2011, 02:50 PM
Hello Nicolas,

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.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
AKROS
Top achievements
Rank 1
answered on 30 Dec 2011, 06:16 PM

Hello Didie,

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:

 

<Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=telerik:GridViewCell}, Converter={StaticResource planningBorderConverter}}"

 

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 :-)

Best Regards,

 

Nicolas

0
AKROS
Top achievements
Rank 1
answered on 03 Jan 2012, 09:39 AM

 

Hi again,

It's definitively not possible to solve the problem like this, since everything is virtualized…
I found another way to fix the problem...

Regards,
Nicolas

 

0
Dimitrina
Telerik team
answered on 03 Jan 2012, 09:45 AM
Hi Nicolas,

 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?

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
AKROS
Top achievements
Rank 1
answered on 03 Jan 2012, 10:45 AM
Hi Didie,

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).

Cheers,
Nicolas
Tags
TreeListView
Asked by
AKROS
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
AKROS
Top achievements
Rank 1
Share this question
or