■ GridViewBase 클래스 : 행/셀 컨텍스트 메뉴에서 셀 값 복사하기

----------------------------------------------------------------------------------------------------

XAML

 

 

<dxg:GridControl x:Name="gridControl">

    <dxg:GridControl.Columns>

        <dxg:GridColumn

            FieldName="UserName"

            Header="User Name" />

        <dxg:GridColumn

            FieldName="RegistrationDate"

            Header="Registration Date" />

    </dxg:GridControl.Columns>

    <dxg:GridControl.View>

        <dxg:TableView x:Name="tableView">

            <dxg:TableView.RowCellMenuCustomizations>

                <dxb:BarButtonItem x:Name="deleteRowBarButtonItem"

                    Content="Delete Row"

                    ItemClick="deleteRowBarButtonItem_ItemClick" />

                <dxb:BarButtonItem x:Name="copyCellDataBarButtonItem"

                    Content="Copy Cell Data"

                    ItemClick="copyCellDataBarButtonItem_ItemClick" />

            </dxg:TableView.RowCellMenuCustomizations>

        </dxg:TableView>

    </dxg:GridControl.View>

</dxg:GridControl>

 

 

C#

 

 

using DevExpress.Xpf.Bars;

using DevExpress.Xpf.Grid;

 

#region Delete Row 바 버튼 항목 항목 클릭시 처리하기 - deleteRowBarButtonItem_ItemClick(sender, e)

 

/// <summary>

/// Delete Row 바 버튼 항목 항목 클릭시 처리하기

/// </summary>

/// <param name="sender">이벤트 발생자</param>

/// <param name="e">이벤트 인자</param>

private void deleteRowBarButtonItem_ItemClick(object sender, ItemClickEventArgs e)

{

    GridCellMenuInfo gridCellMenuInfo = this.tableView.GridMenu.MenuInfo as GridCellMenuInfo;

 

    if(gridCellMenuInfo != null && gridCellMenuInfo.Row != null)

    {

        int rowHandle = gridCellMenuInfo.Row.RowHandle.Value;

 

        this.tableView.DeleteRow(rowHandle);

    }

}

 

#endregion

 

#region Copy Cell Data 바 버튼 항목 항목 클릭시 처리하기 - copyCellDataBarButtonItem_ItemClick(sender, e)

 

/// <summary>

/// Copy Cell Data 바 버튼 항목 항목 클릭시 처리하기

/// </summary>

/// <param name="sender">이벤트 발생자</param>

/// <param name="e">이벤트 인자</param>

private void copyCellDataBarButtonItem_ItemClick(object sender, ItemClickEventArgs e)

{

    GridCellMenuInfo gridCellMenuInfo = this.tableView.GridMenu.MenuInfo as GridCellMenuInfo;

 

    if(gridCellMenuInfo != null && gridCellMenuInfo.Row != null)

    {

        int        rowHandle  = gridCellMenuInfo.Row.RowHandle.Value;

        GridColumn gridColumn = gridCellMenuInfo.Column as GridColumn;

 

        object cellValue = this.gridControl.GetCellValue(rowHandle, gridColumn);

 

        Clipboard.SetText(cellValue == null ? string.Empty : cellValue.ToString());

    }

}

 

#endregion

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요