TreeListView item editing

Grids for WPF Forum

The latest build of this product (v24.1.2) was released 3 months ago, which was before this thread was created.
Posted 22 days ago by John Bell
Version: 24.1.2
Avatar

Hi, I can't get item editing working in my TreeListView.

I'm using an ItemAdapter without a RootItem Binding, i.e. RootItem is set to the ModelView of the page and the ItemAdapter GetChildren returns the heirarchical data from the ViewModel.

The TreeListViewColumn DisplayMemberBinding has Mode=TwoWay. Do I need more then that to tell the TreeListView that the column is potentially editable?

The ItemAdapter GetIsEditable is never called, so none of the cells are editable. Also, some of the items (rows) of the treelistview are readonly so I need to give visual cues to the user which rows are editable, like different background and font weight. I have tried binding a Style DataTrigger for this without success.

My items inherent from a class with implementation taken from the TreeNodeModel sample with an added property for the DataTrigger:

public bool IsReadOnly => !IsEditable;

This is the Cell Style:

<Style x:Key="TreeListViewCell" TargetType="grids:TreeListViewItemCell">
    <!--<Setter Property="TextBlock.Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrush}}"/>-->
    <!--<Setter Property="TextBlock.FontWeight" Value="Bold"/>-->
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=IsReadOnly}">
            <Setter Property="TextBlock.FontWeight" Value="Bold"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

I can't seem to get it work, either using the ItemAdapter GetIsEditable or through bindings.

Thanks for any advice.

Comments (2)

Posted 21 days ago by John Bell
Avatar

I managed to it kind of get it working using the shared:EditableContentControl, but, so far, this control is totally unusable.

1) GetIsEditable only gets called when clicking on cell to try to edit it -> which means there is no way to give visual cues to the user about which rows and fields are editable

2) GetIsEditable is only called to first time I try to enter edit mode, it never gets called again, so I never enter edit mode again after the first edit.

There must be something I'm missing to get this working.

Posted 21 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

The item adapter methods only get called as needed for functionality, as the item adapter is a bridge between the control and its items, which can be of any type.

A DisplayMemberBinding for a TreeListViewColumn will basically put a plain TextBlock in the cells for that column and will not support inline editing. 

Our TreeListViewInlineEditing QuickStart shows an example of using a DataTemplate like this with EditableContentControl to support inline editing:

<DataTemplate x:Key="NameCellDataTemplate">
	<shared:EditableContentControl Content="{Binding Name, Mode=TwoWay}" IsEditing="{Binding IsEditing, Mode=TwoWay}" />
</DataTemplate>

Once something like that is in place, pressing F2 or clicking that column's cell in an already-selected row will try to begin editing.  The item adapter's GetIsEditable method is called at that point to see if editing is supported, but doesn't ever need to be called prior to that for the control to function.

For your first question, that is correct that GetIsEditable is only called when an editing attempt is started.  That being said, as long as the viewmodel data context of your TreeListViewItem has some property on it indicating if it's read-only or not, you should be able to bind to that if you want to change your UI to reflect read-only rows.

In the same QuickStart, I put a breakpoint in DefaultTreeListBoxItemAdapter.GetIsEditable and see it getting called each time I try to edit a row.  It even gets called the second and third time editing the same row.

As for the cell Style from the first post, are you applying that Style via the TreeListViewColumn.CellContainerStyle property?

The setup for this control can get complex since there are several classes involved.  If you require more assistance, please send our support address a new simple sample project showing the issue and reference this thread in your email.  Be sure to exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  The we can debug with that and see what's going on.  Thanks!


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.