0
votes

I want to build a dynamic treeview with checkboxes from database for build a dynamic menu permission for different user’s level. The checkboxes will bind with values and keys. Those checkboxes will show the text and when its checked and saved, I will be able to get the correspond IDs from those checkboxes.

If someone please help me ?

Data in the tables

Menu Header TableA : Here Menu TableA has ID: TableA
ID:   SubMenuHeader:
A1    TableA1
A2    TableA2
A3    TableA3

Menu TableB : Here Menu TableB has ID: TableB
ID:   SubMenuHeader:
B1    TableB1
B2    TableB2
B3    TableB3

TableA1
ID:   SubSubMenuHeader:   RefMenuTable_ID:
C1    TableC1             A1
C2    TableC2             A1
C3    TableC3             A1

The tree should looks like: please imagine the dot (*) as Checkbox

  • TableA
    • TableA1
      • TableC1
      • TableC2
      • TableC3
    • TableA2
    • TableA3
  • TableB
    • TableB1
    • TableB2
    • TableB3

Thanks in advance !

1
i need same requirement . can you please share your solutionSANDEEP

1 Answers

0
votes

You'd have to build an observable data structure of the hierarchy and then bind it to the tree and specify the HierarchialDataTemplate to resolve the nested bindings.

I'm probably define something like:

class ItemClass : INotifyPropertyChanged
{
  public bool IsChecked
  public string Header
  ObservableCollection<ItemClass> Children;
}

Then just build up an ObservableCollection<ItemClass> Items and populate it up from the database. Bind that to the TreeView's ItemsSource, specify the HierarchialDataTemplate and the control template for the TreeViewItem and bind up IsChecked and Header. The HierarchialDataTemplate will tell the TreeView how to recurse through your objects.