zoukankan      html  css  js  c++  java
  • devexpress 的 grid 增加行删除功能

    1、新建UserControl起名为    ContextMenuModule,示例代码如下:

    <UserControl x:Class="Main.UserControls.EvidencePackageList"
                 x:Name="ContextMenuModule"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:Main.UserControls"
                 xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
                 xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
                 xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
                 xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
                 xmlns:dxrudex="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesignerextensions"
                 mc:Ignorable="d" 
                 d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded">

    2、建一个 grid  前台代码示例如下:

                <dxg:GridControl Name="grid" SelectedItemChanged="grid_SelectedItemChanged" MouseDoubleClick="grid_MouseDoubleClick" ContextMenu="{ StaticResource ContextMenu }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <dxg:GridControl.View>
                        <dxg:TableView NavigationStyle="Row" x:Name="gridView" AllowColumnFiltering="False" AllowScrollAnimation="True" ShowGroupPanel="False" ShowGridMenu="GridView_ShowGridMenu">
                            <dxg:TableView.RowCellMenuCustomizations>
                                <dxb:BarButtonItem Name="refresh"
                                               Content="刷新"
                                               ItemClick="Refresh_Click"
                                               Command="{Binding ElementName=ContextMenuModule}"
                                               CommandParameter="{Binding ElementName=ContextMenuModule, Path=CellMenuInfo.Row.RowHandle.Value}" />
                                <dxb:BarButtonItem Name="deleteRow"
                                               Content="删除"
                                               Command="{Binding ElementName=ContextMenuModule,Path=DeleteRow}"
                                               CommandParameter="{Binding ElementName=ContextMenuModule, Path=CellMenuInfo.Row.RowHandle.Value}" />
                            </dxg:TableView.RowCellMenuCustomizations>
                        </dxg:TableView>
                    </dxg:GridControl.View>
    
                    <dxg:GridControl.Columns>
                        <dxg:GridColumn  Header="ID" HorizontalHeaderContentAlignment="Left" FixedWidth="True" FieldName="ID" Width="*" Visible="False" />
                        <dxg:GridColumn  Header="名称" HorizontalHeaderContentAlignment="Left" FixedWidth="True" FieldName="NAME" Width="*" />
                        </dxg:GridColumn>
                    </dxg:GridControl.Columns>
                </dxg:GridControl>

    3、后台加立事件

            public static readonly DependencyProperty CellMenuInfoProperty = DependencyPropertyManager.Register("CellMenuInfo", typeof(GridCellMenuInfo), typeof(EvidencePackageList), new FrameworkPropertyMetadata(null));
            public ICommand DeleteRow { get; private set; }
            public EvidencePackageList()
            {
                DeleteRow = new DelegateCommand<object>(OnDeleteRow);
                InitializeComponent();
            }
    
            public GridCellMenuInfo CellMenuInfo
            {
                get { return (GridCellMenuInfo)GetValue(CellMenuInfoProperty); }
                set { SetValue(CellMenuInfoProperty, value); }
            }

    备注: 

    Command="{Binding ElementName=ContextMenuModule,Path=DeleteRow}"   里的指的是当前用户控件的名称。
  • 相关阅读:
    用jQuery File Upload做的上传控件demo,支持同页面多个上传按钮
    从炉石传说的一个自杀OTK说起
    DTCMS插件的制作实例电子资源管理(二)Admin后台页面编写
    DTCMS插件的制作实例电子资源管理(一)插件目录结构
    一个看似很简单的SQL却难倒了很多人
    一个js验证类
    elasticsearch节点间通信的基础transport
    elasticsearch cluster 详解
    elasticsearch cluster 概述
    Node组装启动过程
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/11834594.html
Copyright © 2011-2022 走看看