dev express 控件使用方法

日前,调试 dev express 14.1.4 使用的中一些方式,记录下来

 

 

 

DEV EXPRESS GRIDcontrol  显示数据的控件

它的一些常用设置

//奇偶行错开显示颜色 

this.gridView1.Appearance.OddRow.BackColor = Color.WhiteSmoke; // 设置奇数行颜色 // 默认也是白色 可以省略
this.gridView1.OptionsView.EnableAppearanceOddRow = true; // 使能 // 和和上面绑定 同时使用有效
this.gridView1.Appearance.EvenRow.BackColor = Color.LightGreen; // 设置偶数行颜色
this.gridView1.OptionsView.EnableAppearanceEvenRow = true; // 使能 // 和和上面绑定 同时使用有效

 

 //填充数据后

  this.gridView1.BestFitColumns();

//自动列宽

 

/// <summary>
/// 显示行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gvRM_IN_YARD_MAIN_CustomDrawRowIndicator(object sender,
DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}

//要注意 ,显示行号的这一列 也要先设置宽度  

gridView1.IndicatorWidth = 30; 

 

 

 

 

//如何让行只能选择而不能编辑(或编辑某一单元格)

(1)、View->OptionsBehavior->EditorShowMode 设置为:Click

(2)、View->OptionsBehavior->Editable 设置为:false

 

如何禁用 GridControl 中单击列弹出右键菜单

设置 Run Design->OptionsMenu->EnableColumnMenu 设置为:false

 

6、如何隐藏 GridControl 的 GroupPanel 表头

设置 Run Design->OptionsView->ShowGroupPanel 设置为:false

 

如何禁用 GridControl 中列头的过滤器 过滤器如下图所示:    

设置 Run Design->OptionsCustomization->AllowFilter 设置为:false

 

如何在查询得到 0 条记录时显示自定义的字符提示/显示 如图所示:

 

方法如下:

//When no Records Are Being Displayed

 

private void gridView1_CustomDrawEmptyForeground(object sender, CustomDrawEventArgs e)

 

{

 

//方法一(此方法为GridView设置了数据源绑定时,可用)

 

ColumnView columnView = sender as ColumnView;

 

BindingSource bindingSource = this.gridView1.DataSource as BindingSource;

 

if(bindingSource.Count == 0)

 

{

 

string str = "没有查询到你所想要的数据!";

 

Font f = new Font("宋体", 10, FontStyle.Bold);

 

Rectangle r = new Rectangle(e.Bounds.Top + 5, e.Bounds.Left + 5, e.Bounds.Right - 5, e.Bounds.Height - 5);

 

e.Graphics.DrawString(str, f, Brushes.Black, r); }

 

//方法二(此方法为GridView没有设置数据源绑定时,使用,一般使用此种方 法)

 

if (this._flag)

 

{ if (this.gridView1.RowCount == 0)

 

{ string str = "没有查询到你所想要的数据!"; Font f = new Font("宋体", 10, FontStyle.Bold);

 

Rectangle r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);

 

e.Graphics.DrawString(str, f, Brushes.Black, r); } } }

 

 

 

9、如何显示水平滚动条?或

 

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

 

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

 

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

 

this.gridView1.OptionsBehavior.Editable = false;

 

this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;

 

组显示

 

OptionsView>OptionsBehavior>AutoExpandAllGroups = True 选择要分组的列,将GroupIndex属性设置为0

 

//动态统计列

gridView2.Columns["列"].SummaryItem.SummaryType =DevExpress.Data.SummaryItemType.Sum;//求和
gridView2.Columns["列"].SummaryItem.DisplayFormat = "{0:0.00}";//格式

 

 

//gridcontrol 控件打印 

 

private void button10_Click(object sender, EventArgs e)
{
PrintingSystem printingSystem1 = new PrintingSystem();
PrintableComponentLink printableComponentLink1 = new PrintableComponentLink();

// Add the link to the printing system's collection of links.
printingSystem1.Links.AddRange(new object[] { printableComponentLink1 });

// 关联控件
printableComponentLink1.Component = gridControl2;

//设置左右间距
printableComponentLink1.Margins.Left = 10;
printableComponentLink1.Margins.Right = 10;
// Set the paper orientation to Landscape.
printableComponentLink1.Landscape = false; //纵向 或横向
printableComponentLink1.PaperKind = System.Drawing.Printing.PaperKind.A4; //纸张
//设置页眉打印标题
PageHeaderFooter phf = printableComponentLink1.PageHeaderFooter as PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(new string[] { "", "进在橱架副食店", "" });
phf.Header.Font = new System.Drawing.Font("宋体", 18, System.Drawing.FontStyle.Bold);
phf.Header.LineAlignment = BrickAlignment.Center;
//设置页眉打印标题


//显示打印预览
printableComponentLink1.ShowPreview( );
//直接打印
// printableComponentLink1.PrintDlg();


}

// 设某一列文字和标题局中显示     

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

//显示过滤格式

  gridView1.OptionsView.HeaderFilterButtonShowMode = DevExpress.XtraEditors.Controls.FilterButtonShowMode.Button;

 

//自定义列显示 小数2位
gridView1.Columns["销售额"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridView1.Columns["销售额"].DisplayFormat.FormatString= "{0:0.00}";

 

//根据单元格内容 把grid单元格 根据条件变色

 

//先注册事件  

 gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);

 

//事件

private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{

if (e.Column.FieldName == "周环比%")
{


int aa = Convert.ToInt32(e.CellValue);
//Convert.ToInt32(gridView1.GetRowCellDisplayText(e.RowHandle, gridView1.Columns["周实绩"].ToString ()));
if (aa <0)
{
//e.Appearance.BackColor = Color.Red ;
e.Appearance.ForeColor = Color.Red;
}
}

}

posted @ 2015-12-17 13:21  最佳拍档  阅读(1187)  评论(0编辑  收藏  举报