DevExpress:XtraGrid里面的GridControl控件使用总结

一.修改列的背景色

复制代码
DevExpress.XtraGrid.StyleFormatCondition cn;

cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, 0);

cn.Appearance.BackColor = Color.Red;

GridView1.FormatConditions.Add(cn);

cn = new DevExpress.XtraGrid.StyleFormatCondition(DevExpress.XtraGrid.FormatConditionEnum.Equal, GridView1.Columns["列名"], null, 1);

cn.Appearance.BackColor = Color.Green;

GridView1.FormatConditions.Add(cn);
复制代码

这样,这列如果值为0则是红色,为1则是绿色

二.如何去除”Drag a Column Header Here To Group by that Column”

DevExpress:XtraGrid里面的GridControl控件使用总结

Views-OptionsView-ShowGroupPanel=False

三.如何禁用GridControl中列头的过滤器

过滤器如下图所示:
设置 Run Design->OptionsCustomization->AllowFilter 设置为:false

四.如何显示水平滚动条?

设置this.gridView.OptionsView.ColumnAutoWidth = false;

五.设置成一次选择一行,并且不能被编辑

 

   this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;

          this.gridView1.OptionsBehavior.Editable = false;

     this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;



 

六.如何显示行号?

复制代码
 this.gridView1.IndicatorWidth = 40;



       //显示行的序号



        private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)



        {



            if (e.Info.IsRowIndicator && e.RowHandle>=0)





            {

                e.Info.DisplayText = (e.RowHandle + 1).ToString();



            }



   }
复制代码

七.如何让各列头禁止移动?

    设置gridView1.OptionsCustomization.AllowColumnMoving = false;

八.如何让各列头禁止排序?

    设置gridView1.OptionsCustomization.AllowSort = false;

九.如何禁止各列头改变列宽?

    设置gridView1.OptionsCustomization.AllowColumnResizing = false;

十.设置单元格自动换行?

1.ColumnEdit 增加 MemoEdit

2.AppearanceCell-TextOptions- WordWrap

3.OptionsView RowAutoHeight

十.设置每一列对齐方式?

View-Appearance-Row-TextOptions-(HAlignment = Center, VAlignment = Center)

十一.设置行只读属性?

GridView.OptionsBehavior-Editable(false)

你可能感兴趣的:(DevExpress)