DevExpress的GridView設置特定行的樣式


GridView控件綁定事件:

            gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell;

根據自定義邏輯來改變行屬性,例子是判斷某個單元格的Is duplicated列是否為yes,若是,則將行標記為黃色。

        //自定義畫某行
        private void gridView_SampleData_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (gridView_SampleData.GetRow(e.RowHandle) == null)
                return;
            else
            {
                //隱藏標記行
                if (gridView_SampleData.Columns["Is duplicated"] != null)
                {
                    gridView_SampleData.Columns["Is duplicated"].VisibleIndex = -1;
                    //獲取所在行指定列的值
                    string duplicated = gridView_SampleData.GetRowCellValue(e.RowHandle, "Is duplicated").ToString();
                    //設置此行的背景顏色
                    if (duplicated == "yes")
                        e.Appearance.BackColor = Color.Yellow;
                }
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM