UltraGrid
private void dxGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e) { foreach (UltraGridRow row in this.grid.Rows) {//根据值设置背景颜色 if (row.Cells["IsAllowEdit"].Value.ToString() == "True") { row.Appearance.BackColor = Color.LightBlue; } if (row.Cells["ConfirmPayApproveID"].Value.ToString() == "3") { row.Appearance.BackColor = Color.LightGreen; } } }
二、UltraGrid多表头代码设置
DateTime currentDateTime=base.GetServerTime(); //当前时间 DateTime currentStartMonth = currentDateTime.AddDays(1 - currentDateTime.Day); //本月月初 DateTime lastStartMonth1 = currentStartMonth.AddMonths(-3); //前三月月初 DateTime lastStartMonth2 = currentStartMonth.AddMonths(-2); //前二月月初 DateTime lastStartMonth3 = currentStartMonth.AddMonths(-1); //前一月月初 this.dxGrid.DisplayLayout.Bands[0].Columns["自驾"].RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly; this.dxGrid.DisplayLayout.Bands[0].Columns["代驾"].RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly; this.dxGrid.DisplayLayout.Bands[0].Columns["SelfDriveFisrtMonthAMount"].Header.Caption =lastStartMonth1.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["SelfDriveSecondMonthAMount"].Header.Caption = lastStartMonth2.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["SelfDriveThirdMonthAMount"].Header.Caption = lastStartMonth3.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["SelfDriveAllMonthAMount"].Header.Caption = "合计"; this.dxGrid.DisplayLayout.Bands[0].Columns["ChauffeurDirveFisrtMonthAMount"].Header.Caption = lastStartMonth1.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["ChauffeurDirveSecondMonthAMount"].Header.Caption = lastStartMonth2.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["ChauffeurDirveThirdMonthAMount"].Header.Caption = lastStartMonth3.ToString("yyyy年MM月"); this.dxGrid.DisplayLayout.Bands[0].Columns["ChauffeurDirveAllMonthAMount"].Header.Caption = "合计"; for (int i = 0; i < this.dxGrid.DisplayLayout.Bands[0].Columns.Count; i++) { this.dxGrid.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle; this.dxGrid.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextHAlign = Infragistics.Win.HAlign.Center; }
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) {//增加行号 e.Layout.Override.RowSelectors = DefaultableBoolean.True; e.Layout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex; e.Layout.Override.RowSelectorWidth = 30; }
隐藏自动创建的列:
grid.UltraGrid().DisplayLayout.NewColumnLoadStyle = NewColumnLoadStyle.Hide;
当前行序号
DataRow currentRow = dt.Rows[gridZY.ActiveRow.RowSelectorNumber - 1];