Zz Oussama Zz Oussama - 9 days ago 7
C# Question

Event Runs many time when AllowRecursiveNodeChecking is true

I have a problem when I use devexpress TreeListView with AllowRecursiveNodeChecking = True the event TreeListView1_OnNodeCheckStateChanged runs many times and I don't know how to do to run it only one time when CheckBox change :

My xaml :

<dxg:TreeListControl.View>
<dxg:TreeListView CustomColumnDisplayText="CustomColumns" ImageFieldName="LineIcon" ShowCheckboxes="True" AllowRecursiveNodeChecking="True" NodeCheckStateChanged="TreeListView1_OnNodeCheckStateChanged" Name="TreeListView1" KeyFieldName="ID" ParentFieldName="ParentID" FontSize="13" NodeImageSize="16,16" ShowNodeImages="True" FontFamily="Segoe UI" FontWeight="Normal" />
</dxg:TreeListControl.View>


In My View :

private void TreeListView1_OnNodeCheckStateChanged(object sender, TreeListNodeEventArgs e)
{

//My Code that run Many Times

}



I Know that I can handle this by Subscribe/Unsubscribe event but I don't know when to do It and AfterEvent does not exist for devexpress TreeListView


Thanks for your Help

Answer

What i have done to avoid this problem :

       public bool ItemChecked = false;

       private void TreeListView1_OnNodeCheckStateChanged(object sender, TreeListNodeEventArgs e)
       {
          ItemChecked = true; 
          // To be sure that our code will run only if checkbox have changed
       }

       private void TreeListView1_OnNodeChanged(object sender, TreeListNodeChangedEventArgs e)
       {
          if (ItemChecked)
          {
           // My Code  
          }

         ItemChecked = false;
        }