1

Here is a piece of my XAML:

    <Grid>
                <dxg:TreeListControl x:Name="HierarchyTreeControl" ItemsSource="{Binding MenuItems}" EnableSmartColumnsGeneration="False" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" SelectionMode="Row" AutoGenerateColumns="None">
                    <dx:TreeListColumn FieldName="Name" Header="Title" Width="50" />
                    <dx:TreeListColumn FieldName="URL" Header="Link" Width="150" />             
                    <dx:TreeListColumn Binding="{Binding HasChildren}" Header="Has any children" Width="20" BestFitArea="Header" AllowResizing="False" ShowInColumnChooser="True" Visible="True" >
                        <dx:TreeListColumn.EditSettings>
                            <dxe:CheckEditSettings />
                        </dx:TreeListColumn.EditSettings>
                    </dx:TreeListColumn>
                    <dx:TreeListColumn Binding="{Binding IsChecked}" Header="Удалить" ReadOnly="False" AllowEditing="{Binding Path=HasChildren, Converter={StaticResource BoolToFalseConverter}, UpdateSourceTrigger=PropertyChanged}" Width="20" BestFitArea="Header" AllowResizing="False" ShowInColumnChooser="True" Visible="True" >
                        <dx:TreeListColumn.EditSettings>
                            <dxe:CheckEditSettings />
                        </dx:TreeListColumn.EditSettings>
                    </dx:TreeListColumn>
                    <dxg:TreeListControl.View>
                        <dxg:TreeListView AllowPerPixelScrolling="True" ShowTotalSummary="False" KeyFieldName="ID" ParentFieldName="ParentID"  TreeDerivationMode="Selfreference" AllowEditing="False" AutoExpandAllNodes="False" FetchSublevelChildrenOnExpand="False" AllowColumnMoving="False" AutoWidth="True" ShowNodeImages="False" />
                    </dxg:TreeListControl.View>
                </dxg:TreeListControl>
            </Grid>

where the source {MenuItems} is ObservableCollection<MenuItem>

I would like to allow to check the checkbox in the last column only if property MenuItem.HasChildren = false

I am trying to do with this code:

AllowEditing="{Binding Path=HasChildren, Converter={StaticResource BoolToFalseConverter}, UpdateSourceTrigger=PropertyChanged}"

But this is not working and I see that converter BoolToFalseConverter calls only once, for the first row

How to complete the task?

Update: Here is the class of MenuItem

public class MenuItem : INotifyPropertyChanged
    {
        private int _id;
        public int ID
        {
            get {return _id;}
            set
            {
                if (_id == value)
                    return;
                _id = value;
                OnPropertyChanged("ID");
            }
        }

        private string _name;
        public string Name
        {
            get{return _name;}
            set
            {
                if (_name == value)
                    return;
                _name = value;
                OnPropertyChanged("Name");
            }
        }

        private string _url;
        public string URL
        {
            get
            {
                return _url;
            }
            set
            {
                if (_url == value)
                    return;
                _url = value;
                OnPropertyChanged("URL");
            }
        }

        private int _target;
        public int Target
        {
            get{return _target;}
            set
            {
                if (_target == value)
                    return;
                _target = value;
                OnPropertyChanged("Target");
            }
        }
        private int? _parentID;
        public int? ParentID
        {
            get{return _parentID;}
            set
            {
                if ((_parentID == null && value == null) || _parentID == value)
                    return;
                _parentID = value;
                OnPropertyChanged("ParentID");
            }
        }

        public bool HasChildren { get; set; }

        private bool _isChecked;
        public bool IsChecked
        {
            get{return _isChecked;}
            set
            {
                if (_isChecked == value)
                    return;
                _isChecked = value;
                OnPropertyChanged("IsChecked");
            }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

1 Answer 1

1

I assume HasChildren refers to "view" children. In this case you need to a dedicated converter (or better yet a behavior) that will publish an event. The view model will subscribe to the event, and once received it will either set to true or false the value of HasChildren and notify the Is Checked property to notify the view.

If HasChildren relates to a viewmodel object than it is simply a manner of boll check in the view model and notify the view.

Update from the comments:

I found this question in DevExpress forum which talk exactly about your question => devexpress.com/Support/Center/Question/Details/Q367068 They are saying there you should use the TreeListView.ShowingEditor Event which when called you can set to enable or disable the editing of particular cells

Sign up to request clarification or add additional context in comments.

5 Comments

HasChildren gets its value some way, my guess by your comment is that it is from a field. I would suggest changing the property HasChildren to get & internal set so it will not be changeable from outside the class, and then in the "set" method update the value of IsChecked.
I dont want to update HasChildren property. My idea is change AllowEditing property of the checkbox, based on HasChildren value for every row in treeview.
Just a fix from above code update: You property HasChildren is not readonly, it simply does not have a backend field. Giving it a backend field will not change its behavior in any way. And back to your question - I found this question in DevExpress forum which talkjs exactly about your question => devexpress.com/Support/Center/Question/Details/Q367068 They are saying there you should use the TreeListView.ShowingEditor Event which when called you can set to enable or disable the editing of particular cells.
Thank you very much! Your link to DevExpress forum saved me! Wish I could mark your comment as the answer!
@Beingbigone Don`t forget to mark the answer as the correct one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.