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

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.ManiWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800"
    Height="600"
    Title="특정 값을 갖는 행 선택하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"    />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <dxg:GridControl x:Name="gridControl" Grid.Row="0"
            AutoGenerateColumns="AddNew"
            SelectionMode="Row">
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tableView" />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <Button Grid.Row="1"
            HorizontalAlignment="Center"
            Margin="10"
            Width="100"
            Height="30"
            FontSize="16"
            Content="Select"
            Click="button_Click" />
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;

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

        #region 생성자 - MainWindow()

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

            this.gridControl.ItemsSource = ProductList.GetData();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            SelectProduct(20);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 제품 선택하기 - SelectProduct(minimumPrice)

        /// <summary>
        /// 제품 선택하기
        /// </summary>
        /// <param name="minimumPrice">최소 가격</param>
        private void SelectProduct(double minimumPrice)
        {
            this.gridControl.BeginSelection();

            this.gridControl.UnselectAll();

            for(int i = 0; i < this.gridControl.VisibleRowCount; i++)
            {
                int rowHandle = this.gridControl.GetRowHandleByVisibleIndex(i);

                if(!this.gridControl.IsGroupRowHandle(rowHandle))
                {
                    double unitPrice = (double)this.gridControl.GetCellValue(rowHandle, this.gridControl.Columns["UnitPrice"]);

                    if(unitPrice >= minimumPrice)
                    {
                        this.gridControl.SelectItem(rowHandle);
                    }
                }
            }

            this.gridControl.EndSelection();
        }

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

댓글을 달아 주세요