첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" 
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800" 
    Height="600"
    Title="셀 값 변경 후 데이터 소스에 값을 즉시 저장하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <dxg:GridControl x:Name="gridControl"
            ItemsSource="{Binding Products}">
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="ProductName">
                    <dxg:GridColumn.EditSettings>
                        <dxe:ComboBoxEditSettings x:Name="productNameComboBoxSettings"
                             DisplayMember="ProductName"
                             ValueMember="ProductName" />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="UnitPrice">
                    <dxg:GridColumn.EditSettings>
                        <dxe:SpinEditSettings
                            MinValue="1"
                            MaxValue="999" />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="Discontinued" />
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView CellValueChanging="tableView_CellValueChanging" />
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;

using DevExpress.Xpf.Grid;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.productNameComboBoxSettings.ItemsSource = new NorthwindData().Products;

            this.gridControl.ItemsSource = new NorthwindData().Products;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 테이블 뷰 셀 값 변경할 경우 처리하기 - tableView_CellValueChanging(sender, e)

        /// <summary>
        /// 테이블 뷰 셀 값 변경할 경우 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void tableView_CellValueChanging(object sender, CellValueEventArgs e)
        {
            TableView tableView = sender as TableView;

            tableView.PostEditor();

            Title = tableView.Grid.GetCellValue(e.RowHandle,e.Column.FieldName).ToString();
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요