1. 去除 GridView 头上的 "Drag a column header here to group by that
column"
点击 Run Designer -> 找到:OptionView -> 将 ShowGroupPanel : 设置为 false ;
2. 如何显示出 GridView 自带的 搜索功能
点击 Run Designer -> 找到: OptionsFind -> 将AlwaysVisible : 设置为 True
3. 如何将GridView 的大小自适应窗体的大小
右键 GridView 控件 -> 属性 -> 找到 Dock : 设置为 Fill
4. 当GridView数据源发生变化时,如何更改GridView所"绑定的值"
Code 注 : 其实就是重新创建了一个GridView的实例。
1 gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView(gridControl1);
2 gridControl1.MainView = gridView1;
3 gridView1.OptionsView.ShowGroupPanel = false;
4 gridView1.OptionsFind.AlwaysVisible = true;
5 gridControl1.DataSource = dt;
5. 让GridView行不可编辑
Run Designer -> OptionsBehavior -> Editable : False
6. GirdView行添加Button按钮之后,触发事件不可用.
将GridView Editable 设置为True
让GridView可编辑,如果不想让它可编辑的话,在一列一列的进行设置.原因是:将GridView设置为不可编辑之后,那么鼠标点击Button那一列只是选中而已,不会进行触发事件.
7. GridView 设置选中行的颜色
GridView : Run Designer -> Appearences : selectRow & FocusedRow
(两项都要设置)BackColor : MediumSlateBlue 背景色
ForeColor : White 前景色 字体颜色
8. GridView 设置标题行颜色
GridView : Run Designer -> Appearences : HeadPanel
在这个属性组中都是关于标题行的设置,再次不做诠释.当设置完HeadPanel 其实并没有结束,是不显示效果的, 还需要设置 GridControl 属性中 LookAndFeel :
Style 设置为ultraFlat , UseDefaultLookAndFeel 设置为 False .
9. 在GridView 行中添加Button按钮
1 public void ButtonInitial()
2 {
3 RepositoryItemButtonEdit rib = new RepositoryItemButtonEdit();
4 rib.TextEditStyle = TextEditStyles.HideTextEditor;
5 rib.Buttons[0].Kind = ButtonPredefines.Glyph;
6 rib.ButtonClick += rib_ButtonClick;
7 rib.Buttons[0].Caption = "详细信息";
8 rib.Buttons[0].Visible = true;
9 gridView1.Columns["DOWNSTATE"].ColumnEdit = rib;
10
11 }
12
13 void rib_ButtonClick(object sender, ButtonPressedEventArgs e)
14 {
15 int rowindex = gridView1.FocusedRowHandle;
16 DataRow row = gridView1.GetDataRow(rowindex);
17 }
10. GridView 设置标题行以及内容行 数据居中
标题行 10 所述 在HeadPanel 里有一个TextOptions 展开之后 将HAlignment : Center
如果是将内容行数据居中.有两种方法
①逐行设置
①GridView -> Run Designer -> Columns -> AppearanceCell ->
TextOptions 找到HAlignment : Center .②设置Appearences
GridView -> Run Designer -> Appearance -> ViewCaption -> TextOptions
-> HAlignment : Center
11.GridView添加CheckBox 并支持多选操作
GridView : Run Designer -> OptionsSelection -> MultiSelect : True
MultiSelectMode : CheckBoxRowSelect
12.GridView 添加 序号 列
GridView : Run Designer -> Event -> CustomDrawRowIndicator
在事件中添加代码 :
1 e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
2 if (e.Info.IsRowIndicator)
3 {
4 if (e.RowHandle >= 0)
5 {
6 e.Info.DisplayText = (e.RowHandle + 1).ToString();
7 }
8 else if (e.RowHandle < 0 && e.RowHandle > -1000)
9 {
10 e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
11 e.Info.DisplayText = "G" + e.RowHandle.ToString();
12 }
13 }
另外在 Run Desginer -> IndicatorWidth 设置序号列的宽度 一般30左右就比较适合一些了.
GridView内容打印
1. private void btnPrint_Click(object sender, EventArgs e)
2. {
3.
4. PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem());
5. link.Component = this.gridUser;
6. link.Landscape = true;
7. link.PaperKind = System.Drawing.Printing.PaperKind.A3;
8. link.CreateMarginalHeaderArea += new CreateAreaEventHandler(Link_CreateMarginalHeaderArea);
9. link.CreateDocument();
10. link.ShowPreview();
11. }
获取某行某列值
this.gridView1.GetRowCellValue(行号, 列名).ToString().Trim() 3) 自定义文本
1. #region 事件自定义列显示
2. /// <summary>
3. /// 自定义列显示
4. /// </summary>
5. private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
6. {
7.
8. if (e.Column.FieldName == "列名")
9. {
自定行序号
1. #region 事件_gridView2序号设置
2. /// <summary>
3. /// 序号设置
4. /// </summary>
5. private void gridView1_CustomDrawRowIndicator(object sender,
DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
6. {
7.
8. e.Info.Appearance.TextOptions.HAlignment =
DevExpress.Utils.HorzAlignment.Center;
9. if (e.RowHandle >= 0)
10. {