728x90
728x170

Grid 에 Data 가 정형화 되어있지 않은 경우 특정 셀의 컬럼에 길이 제한을 두고 싶을 때 사용하는 방법입니다.
아래는 LOT 컬럼이 5자가 넘는 경우 처리하는 방법으로 아래처럼 표시가 됩니다.

using System.Collections.Generic;
using System.Windows.Forms;

using DevExpress.XtraGrid.Views.Grid.ViewInfo;

namespace WindowsFormsApp
{
    public partial class MainForm : Form

    {
        public MainForm()
        {
            InitializeComponent();

            this.gridView.ValidatingEditor += GridView_ValidatingEditor;

            TestData testData1 = new TestData();
            testData1.LOT = "L001";
            testData1.WAFER = "01";

            TestData testData2 = new TestData();
            testData2.LOT = "L001";
            testData2.WAFER = "02";

            List<TestData> testDatas = new List<TestData>();
            testDatas.Add(testData1);
            testDatas.Add(testData2);
            this.gridControl.DataSource = testDatas;
        }

        void GridView_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {
            string value_string = e.Value.ToString();
            GridViewInfo viewInfo = gridView.GetViewInfo() as GridViewInfo;
            GridCellInfo cellInfo = viewInfo.GetGridCellInfo(gridView.FocusedRowHandle, gridView.FocusedColumn);

            if (cellInfo.Column.FieldName == "LOT")
            {
                if (value_string.Length > 5)
                {
                    e.ErrorText = "The value is too long";
                    e.Valid = false;
                }
            }
        }

        class TestData
        {
            public string LOT { get; set; }
            public string WAFER { get; set; }
        }
    }
}


728x90
그리드형
Posted by kjun
,