Hello!
I have a question about Hierarchy and IsExpandable, In my GridView ,user can add and remove father and son items.
I tried the code like this two way,they can set IsExpandable to false or true when loaded or add items,
but when I remove all the sub items of a father item, the IsExpandable can not set to false,is there any way to solve it? thanks a lot.
<
telerik:RadGridView.RowStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"IsExpandable"
Value
=
"True"
/>
<
Style.Triggers
>
<
DataTrigger
Binding
=
"{Binding Converter={StaticResource integerToBooleanConverter}, Path=SubList.Count}"
Value
=
"False"
>
<
Setter
Property
=
"IsExpandable"
Value
=
"False"
/>
</
DataTrigger
>
</
Style.Triggers
>
</
Style
>
</
telerik:RadGridView.RowStyle
>
<
i:Interaction.Behaviors
>
<
behavior:IsExpandableBehavior
IsExpandableSourcePropertyName
=
"SubList.Count"
/>
</
i:Interaction.Behaviors
>
13 Answers, 1 is accepted
As it turns out, there's an issue with the expanding of RadGridView that breaks the binding to the IsExpandable property. I've logged this in our system and you can follow the process of fixing it in our feedback portal. As a thank you for helping us find this issue, I've awarded you with some Telerik points.
I've attached a sample project, showing how you can achieve the desired behaviour through a style selector. Please let me know if this workaround works for you.
Regards,
Dilyan Traykov
Telerik
hello Dilyan Traykov,
Thanks for your demo,it worked fine!
but in my project, the gridrow can be drag & drop to order,so I set RowStyle like this:
<
telerik:RadGridView.RowStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"telerik:DragDropManager.AllowDrag"
Value
=
"True"
/>
<
Setter
Property
=
"telerik:DragDropManager.TouchDragTrigger"
Value
=
"TapAndHold"
/>
<
Setter
Property
=
"IsExpandable"
Value
=
"True"
/>
<
Style.Triggers
>
<
DataTrigger
Binding
=
"{Binding Converter={StaticResource integerToBooleanConverter}, Path=SubList.Count}"
Value
=
"False"
>
<
Setter
Property
=
"IsExpandable"
Value
=
"False"
/>
</
DataTrigger
>
</
Style.Triggers
>
</
Style
>
</
telerik:RadGridView.RowStyle
>
then,the grid can be drag & drop, but can't set IsExpandable accurately.
can you tell me how to fix it? thank you very much!
And is it possible to write a common class like your MyStyleSelector class?
improve the code:
if ((item as Division).Teams.Count > 0)
to a common way?
Another solution I can offer is to handle the Deleted event of the GridView and set the IsExpandable property there:
private
void
parentGrid_Deleted(
object
sender, GridViewDeletedEventArgs e)
{
var childGrid = e.OriginalSource
as
RadGridView;
if
(childGrid.Items.Count == 0)
{
childGrid.ParentRow.IsExpanded =
false
;
childGrid.ParentRow.IsExpandable =
false
;
}
}
I've attached a sample project, showing you how to implement this. Let me know whether this approach works for you.
Regards,
Dilyan Traykov
Telerik
Hello Dilyan Traykov,
I tried your demo,when I deleted all the sub items of first row, the IsExpandable of first row setted to false,
but when I deleted all the sub items of second row too,the IsExpandable of first row setted to ture.
so in the grid,only one row's IsExpandable can be setted to false in this demo.
can you resolve it?
Another quistion: RowStyleSelector and RowStyle can't be used in one gridview?
The behavior you're experiencing is due to RowVirtualization. Disabling it fixes the issue, but I should warn you that this is highly unrecommended as it leads to degraded performance.
Regarding your second question - the RowStyle and RowStyleSelector are not meant to work together. As you have probably seen, the RowStyleSelector is overwritten by the RowStyle. The same behavior is observed with the standard MS controls. So I'm afraid there is no way to apply both.
Could you please specify the scenario in which you would like to use them? Maybe I can provide you with a solution using just one.
Feel free to approach me with any further questions you might have.
Regards,
Dilyan Traykov
Telerik
Hello Dilyan Traykov,
In my project,
1.I should write a RadGridView with three layers hierarchy.
2.User can click buttons in toolbar to add\edit\delete items of all layers.
3.User can drag & drop a item between same layer to order the data.
4.If one row has no subItems or subItems are deleted, set the IsExpandable to false.
that are all I want to achieve, waiting your solution eagerly! thank you!
I seem to have found a solution for your scenario without the need to disable virtualization. It incorporates both previous approaches and relies on both a RowStyleSelector and the Deleted event. I've attached the sample project to my reply. Please take a look at it and let me know whether this behavior is satisfactory for you.
Do let me know if any further questions arise.
Regards,
Dilyan Traykov
Telerik
Hello Dilyan Traykov,
It worked fine when I delete all the sub items of one row as A,but when I add a sub item to the SubList of A by click a button,the IsExpandable was always false,so I can not see the sub item added.
before I use the demo,when I add a sub item to the SubList of A, the IsExpandable was set to true,and the gridview would add a subgrid newrow automatically.
I think if I do something in the add sub item button click event, to set IsExpandable to true of the gridrow, it will work fine,but I use MVVM, I do not want to operate View in ViewModel, is there some other solution to solve it perfectly?
I'm afraid this is the only solution I can offer you at the moment until we fix the binding issue.
You can follow the item in our feedback portal in order to get notified when the bug is fixed.
Regards,
Dilyan Traykov
Telerik
Hello Dilyan Traykov,
Thanks for your reply.
I have another problem,I was disturbed about the drag & drop in Hierarchy, I want to drag & drop a item between same layer to order the data in Hierarchy.
I have seen the toppic , but I have no idea to remodify it, could you do me a favor to send me a sample project, show me how to do that? thank you a lot! best wishes!
I'm attaching a sample project, that implements the desired behavior. Feel free to modify it to your liking.
I noticed that you have opened another thread regarding the same question where one of my colleagues has responded. Could you please take a look at it as well?
Regards,
Dilyan Traykov
Telerik