winform Dev GridView 控件常用属性总结

Dev GridControl GridView常用属性

1.隐藏最上面的GroupPanel:

  gridView1.OptionsView.ShowGroupPanel=false; 

2.得到当前选定记录某字段的值:

  sValue=Table.Rows[gridView1.FocusedRowHandle][FieldName].ToString();  

3.数据只读:

  gridView1.OptionsBehavior.Editable=false;  

4.不显示MasterDetailView:

  gridView1.OptionsDetail.EnableMasterViewMode=false;  

5.修改最上面的GroupPanel内容:

   gridView1.GroupPanelText="奔跑ing";  

6.设置数据源:

   gridControl1.DataSource = dt;

7.读写拷贝权限设置:

  只读不可拷贝:

    ColumnView.OptionsBehavior.Editable = False  

  只读可拷贝:

    ColumnView.OptionsBehavior.Editable = True

    OptionsColumn.AllowEdit = True

    OptionsColumn.ReadOnly = True

    e.g.  

            gv_order.OptionsBehavior.Editable = true;
            gv_order.Columns["Value"].OptionsColumn.AllowEdit = true;
            gv_order.Columns["Value"].OptionsColumn.ReadOnly = true;

  可编辑:

    ColumnViewOptionsBehavior.Editable = True

    OptionsColumn.AllowEdit = True

    OptionsColumn.ReadOnly = False  

8.模板列的设置:

  到Columns中,在他的属性中找到ColumnEdit.

  以LookUpEdit为例:

  首先从Designer左边菜单In-Place Editor Repository中添加LookUpEdit.取名为Re1.然后.在他的Columns属性中添加3列.Caption依次为:编号,姓名,性别.FieldName依次为:FID,FNAME,FSEX.然后将Re1的NullText设置成空.

  AutoSearchColumnIndex属性设置为2.ImmediatePopup属性设置为True.

  SearchMode设置为OnlyInPopup.

  然后将这个模板列附加到我们上面提到的列1(也就是将列1的ColumnEdit属性设成Re1)

  最后我们还要在代码里面给Re1绑定数据源和显示项.

         Re1.DataSource = DALUse.Query("select fid,fname,fsex from dual").Tables[0];

         Re1.DisplayMember = "FSEX";

         Re1.ValueMember = "FNAME";  

9.设某一列文字和标题局中显示:

   gridView1.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

   gridView1.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;   

10.去掉某一列上面的自动筛选功能(Filter):                  

   gridView1.Columns[0].OptionsFilter.AllowAutoFilter = false;

   gridView1.Columns[0].OptionsFilter.AllowFilter = false;                

   gridView1.Columns[0].OptionsFilter.ImmediateUpdateAutoFilter = false;   

11.设置冻结列(左冻结):

  gridView1.Columns[0].Fixed= DevExpress.XtraGrid.Columns.FixedStyle.Left;   

12.得到单元格数据(0行0列):

   string ss=gridView1.GetRowCellDisplayText(0, gridView1.Columns[0]);

   string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);   

13.设置单元格数据:

   gridView1.SetRowCellValue(0, gridView1.Columns[0], "123");   

14.设置自动增加的行号,需要先添加给gridview添加事件CustomDrawRowIndicator    

private void gridview_CustomDrawRowIndicator(object sender,DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)

    {

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

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

    }  

15、如何让各列头禁止移动? 

设置 gridView1.OptionsCustomization.AllowColumnMoving = false

 

16、如何让各列头禁止排序? 

设置 gridView1.OptionsCustomization.AllowSort = false

 

17、如何禁止各列头改变列宽? 

设置 gridView1.OptionsCustomization.AllowColumnResizing = false

18 根据数据样式显示不同的效果

private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            string accountQuantity = gridView1.GetRowCellValue(e.RowHandle, "ACCOUNT_QUANTITY").ToString();
            string actualQuantity = gridView1.GetRowCellValue(e.RowHandle, "ACTUAL_QUANTITY").ToString();
            if (accountQuantity != actualQuantity)
            {
                // e.Appearance.BackColor = Color.Red;//改变背景色
                e.Appearance.ForeColor = Color.Red;//改变字体颜色
            }
            if (e.DisplayText.ToString().Equals("0001-01-01"))
            {
                e.DisplayText = string.Empty;
            }
            if (e.DisplayText.ToString().Equals("0001-01-01 00:00:00"))
            {
                e.DisplayText = string.Empty;
            }
        }

19, 显示进度条

   /// 
        /// 自定义进度条列
        /// 
        /// 
        /// 列的字段名
        /// 
        /// 
        /// 
        public static void CustomProgressBarColumn(DevExpress.XtraGrid.Views.Grid.GridView view, string fieldName, int warningValue, Brush lessColor , Brush greaterColor)
        {
            var col = view.Columns[fieldName];
            if (col == null) return;
            col.AppearanceCell.Options.UseTextOptions = true;
            col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            view.CustomDrawCell += (s, e) =>
            {
                if (e.Column.FieldName == fieldName)
                {
                    DrawProgressBar(e,warningValue,lessColor,greaterColor);
                    e.Handled = true;
                    DrawEditor(e);
                }
            };
        }
        static void DrawProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e, int warningValue , Brush lessColor, Brush greaterColor)
        {
            double percent = e.CellValue == null ? 0 : (double)e.CellValue;
            int width = (int)(percent * e.Bounds.Width);
            Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, width, e.Bounds.Height);
 
            Brush b = Brushes.Green;
            if (greaterColor != null)
            {
                b = greaterColor;
            }
            if (percent*100  < warningValue)
            {
                if (lessColor == null)
                {
                    b = Brushes.Red;
                }
                else
                {
                    b = lessColor;
                }
            }
            e.Graphics.FillRectangle(b, rect);
        }
	static void DrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            GridCellInfo cell = e.Cell as GridCellInfo;
            Point offset = cell.CellValueRect.Location;
            BaseEditPainter pb = cell.ViewInfo.Painter as BaseEditPainter;
            AppearanceObject style = cell.ViewInfo.PaintAppearance;
            if (!offset.IsEmpty)
                cell.ViewInfo.Offset(offset.X, offset.Y);
            try
            {
                pb.Draw(new ControlGraphicsInfoArgs(cell.ViewInfo, e.Cache, cell.Bounds));
            }
            finally
            {
                if (!offset.IsEmpty)
                {
                    cell.ViewInfo.Offset(-offset.X, -offset.Y);
                }
            }
        }

 

你可能感兴趣的:(C#,winform,DevExpress,控件)