TreeListView and ContextMenu

2 posts, 0 answers
  1. Carlos
    Carlos avatar
    3 posts
    Member since:
    May 2013

    Posted 05 Jun 2013 Link to this post

    Hi, i am new using telerik controls.

    How can i show different items on my contextmenu for some rows in my TreeListView?

    This is my xaml code.

    <telerik:RadTreeListView AutoExpandItems="{Binding IsChecked,  ElementName=AutoExpandItemsCheckBox, Mode=TwoWay}"
                                   x:Name="tlvPlanCuenta" CanUserReorderColumns="False" CanUserSortColumns="False" ColumnWidth="*"
                                   IsReadOnly="True" MinHeight="300"  RowIndicatorVisibility="Collapsed"  HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch" AutoGenerateColumns="False" BorderThickness="1" CanUserResizeColumns="True"  
                                   FontSize="12"  GridLinesVisibility="Both" Grid.Row="1" SelectionChanged="tlvPlanCuenta_SelectionChanged" FontStyle="Normal">
     
     
              <!--Child Definitions-->
              <telerik:RadTreeListView.ChildTableDefinitions>
                  <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
              </telerik:RadTreeListView.ChildTableDefinitions>
     
              <!--Context Menu-->
              <telerik:RadContextMenu.ContextMenu>
                  <telerik:RadContextMenu x:Name="ContextMenuPlanCuenta"  Placement="MousePoint" ItemClick="ContextMenu_ItemClick"  Opened="OnMenuOpened">
                      <telerik:RadContextMenu.Items>
                          <telerik:RadMenuItem x:Name="ItemMenuAdd" Header="Añadir Cuenta"/>
                          <telerik:RadMenuItem x:Name="ItemMenuEdit" Header="Editar Cuenta" />
                          <telerik:RadMenuItem x:Name="ItemMemuDelete"  Header="Quitar Cuenta" />
                      </telerik:RadContextMenu.Items>
                  </telerik:RadContextMenu>
              </telerik:RadContextMenu.ContextMenu>
     
               
              <!--Columnas-->
              <telerik:RadTreeListView.Columns>
                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=CuentaSinSeparador}" Header="Cuenta Contable" Width="500"  />
                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=CuentaConSeparador}" Header="Cuenta Contable" IsVisible="False" Width="500" />
                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=IsAnalitica}" Header="Analítica" Width="100" ShowFieldFilters="False"/>
                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Rubro}" Header="Rubro"  Width="100" ShowFieldFilters="False"/>
                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Nivel}" Header="Nivel" IsVisible="False"  Width="100" ShowFieldFilters="False"/>
              </telerik:RadTreeListView.Columns>
     
          </telerik:RadTreeListView>


    and this is my cs code:

    private void OnMenuOpened(object sender, RoutedEventArgs e)
    {
        RadContextMenu menu = (RadContextMenu)sender;
        GridViewRow row = menu.GetClickedElement<GridViewRow>();
     
        if (row != null)
        {
            row.IsSelected = row.IsCurrent = true;
            var selectedAccount = (Account)row.Item;
            if (cuentaSeleccionada.Nivel == 1)
                menu.IsOpen = false;
        }
        else
        {
            menu.IsOpen = false;
        }
    }
     
     
    private void ContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
    {
        RadContextMenu menu = (RadContextMenu)sender;
        RadMenuItem clickedItem = e.OriginalSource as RadMenuItem;
        GridViewRow row = menu.GetClickedElement<GridViewRow>();
     
     
        var selectedAccount = (Account)row.Item;
     
        if (clickedItem != null)
        {
            switch (clickedItem.Name)
            {
                case "ItemMenuAdd":
                          //process 1
                    break;
                case "ItemMenuEdit":
                          //process 2
                    break;
                default:
                    break;
            }
        }
    }


    Thanks.

    ps. Sorry about my english, i speak spanish.
  2. Carlos
    Carlos avatar
    3 posts
    Member since:
    May 2013

    Posted 06 Jun 2013 Link to this post

    no answer? :(
  3. DevCraft banner
Back to Top