玩转DevExpress.XtraGrid.view.gridview

(一)双击展开,收缩字表
Private Sub ExpandedChild(ByVal sender As DevExpress.XtraGrid.Views.Grid.GridView)
'找出焦点行
Dim VIntPage As Integer = sender.FocusedRowHandle
If sender.GetMasterRowExpanded(VIntPage) Then
sender.CollapseMasterRow(VIntPage)
Else
sender.ExpandMasterRow(VIntPage)
End If
End Sub

(二)单击选中某行的checkbox
Private Sub GridChecked(ByVal sender As DevExpress.XtraGrid.Views.Grid.GridView, ByVal TableIndex As Integer)
Try
'找出焦点行做在的内存表中所在的行
Dim rowPlace As DataRow = CType(sender, GridView).GetDataRow(CType(sender, GridView).FocusedRowHandle)
'SELECTED为checkbox的字段名(1:选中,0:不选中)
If rowPlace("SELECTED") = 1 Then
rowPlace("SELECTED") = 0
Else
For Each VRow As DataRow In objLowerPriceQueryOut.Info.Tables(TableIndex).Rows
VRow!SELECTED = 0
Next
rowPlace("SELECTED") = 1
End If
Catch ex As Exception
End Try
End Sub

(三)设置gridview只读属性options->optionsbehavior->editable为false
设置单击选中该列,而不是单元格options->optionsSelction
->EnableApperanceFocusedCell为false

(四)将gridview中某一字段设置为RepositoryItemHyperLinkEdit,要触发该链接的事件,可以在In_place Editor Repository中触发click 事件。但是,触发该事件的同时,gridview中的OptionBehavior->Editable必须设置为true。

(五)在gridview中绑定内存表,要改变焦点行某一字段的值
'根据gridview的焦点行获取内存表的行数
Dim rowGoMain As DataRow = gridview.GetDataRow(sender.FocusedRowHandle)
'修改该行的值
rowGoMain("字段名") = "aa"

(六)对DataSet进行查询:
ds.Tables[0].DefaultView.RowFilter = "查询条件";

(七) 设置展开第一行的字表
gridview.SetMasterRowExpanded(1, True)

(八)设置gridview某一列汇总:选中该列,在SummaryItem设置相应属性即可。DisplayFormat为显示的格式,FieldName为需要汇总的字段……

(九)设置gridview单元格自动换行:在单元格中一个Memo控件,columnedit->new->MemoEdit,gridview中设置optionsview->rowautoheight=true

 

 

 

 

Options        
OptionsBehavior       视图的行为选项
  AllowIncrementalSearch     允许用户通过输入想得到的列值来定位行
  AllowPartialRedrawOnScrolling     允许视图在垂直滚动中局部刷新
  AutoExpandAllGroups     自动展开视图中的所有组
  AutoPopulateColumns     当视图中没有某些数据源中的字段时,在视图中自动创建这些列
  AutoSelectAllInEditor     在一个单元格编辑中,是否允许通过Enter或F2来选择该单元格的所有内容
  AutoUpdateTotalSummary     当列值发生改变时,自动更新汇总摘要数据
  CacheValuesOnRowUpdating     缓冲将被存入数据源的数据(当一行数据要存入到数据源时,Grid可以将它的值存入到一个内部的缓冲器中。这样,万一那行数据在存入时被数据源的检查机制清空了,还可以恢复)
  Editable     允许对单元格进行编辑
  EditorShowMode     设置鼠标激活单元格编辑器的模式
  FocusLeaveOnTab     如果在Grid中TAB键被禁止,是否在按下TAB键时将焦点移到下一个控件
  ImmediateUpdateRowPosition     因为排序、分组和过滤设置造成行的数据被修改时,是否立即更新一行的位置
  KeepFocusedRowOnUpdate     当后台的数据记录变化时,保持焦点行的焦点
  KeepGroupExpandedOnSorting     当数据进行排序时,保持行的扩展状态
  SmartVertScrollBar     设置是否能滚动视图到第一行和最后一行
OptionsCustomization       访问视图的用户化操作
  AllowChangeBandParent     允许用户能够移动带子在父母中?
  AllowChangeColumnParent     允许用户能够在带子中移动列
  AllowColumnMoving     允许用户通过拖动列头来移动列
  AllowColumnResizing     允许用户修改列宽
  AllowFilter     允许用户对数据进行过滤操作
  AllowGroup     允许用户对数据进行分组操作
  AllowRowSizing     允许用户修改行高
  AllowSort     允许用户对数据进行排序操作
  ShowBandsInCustomizationForm     在用户窗体中显示带子(BandedGridView和AdvBandedGridView专有属性)
OptionsDetail       对视图的主要明细操作
  AllowExpandEmptyDetails     没有明细数据时,主行能够展开
  AllowOnlyOneMasterRowExpanded     同时只允许展开一个主行
  AllowZoomDetails     允许视图的明细扩大到整个控件的区域
  AutoZoomDetail     当相应的主行展开时,自动把视图的明细扩大到控件的区域
  EnableDetailToolTip     允许明细上的提示出现
  EnableMasterViewMode     允许显示视图的明细
  ShowDetailTabs     显不Tab的明细
  SmartDetailExpand     当详细视图扩展时,是否自动进行滚动,使该详细视图的所有行都显示出来
  SmartDetailExpandButtonMode     设置"主—明细"扩展按钮的风格
  SmartDetailHeight     (保留属性)
OptionsFilter       视图的过滤操作
  AllowColumnMRUFilterList     在列过滤器下拉打开时,显示最近用于过滤的项目(MRU=the most recently used)
  AllowFilterEditor     允许使用过滤编辑器(用于复杂过滤标准的设置)
  AllowMRUFilterList     允许使用最近使用项目的过滤列表
  ColumnFilterPopupMaxRecordsCount     设置过滤的下拉菜单中所能显示的最大记录数
  ColumnFilterPopupRowCount     列过滤器下拉时能弹出的最大项目数量
  MRUColumnFilterListCount     是否存放最近使用过的视图列的过滤项目
  MRUFilterListCount     是否存放最近使用过的视图的过滤条件
  MRUFilterListPopupCount     最近使用过的过滤列表中能显示的项目数
  ShowAllTableValuesInFilterPopup     是否在下拉列表中显示所有记录的(唯一的)值,或者满足过滤标准的值
  UseNewCustomFilterDialog     高级用户用定制的过滤器对话框
OptionsHint       视图的提示操作
  ShowBandHeaderHints     显示表格带头被截去的内容(BandedGridView和AdvBandedGridView专有属性)
  ShowCellHints     显示单元格被截去的内容
  ShowColumnHeaderHints     显示列头被截去的内容
OptionsLayout       视图的布局操作
  Columns    
    AddNewColumns   存在于当前控件,但不存在于布局的列,当它恢复时将被保留?
    RemoveOldColumns   恢复时存在于布局中的,但不存在于当前控件的列,将被丢弃或者加入到控件中
    StoreAllOptions   当布局进行存储或恢得时,控件所有的列/带(除了外观设置外)的设置都将被存储或恢得
    StoreAppearance   存储或恢复外观设置
    StoreLayout   能否存储或恢复布局
  LayoutVersions     布局的版本
  StoreAllOptions     存储或恢复控件的所有设置(除外观设置或样式条件外)
  StoreAppearance     存储或恢复控件的外观设置
  StoreDataSettings     存储或恢复控件的分组、排序、过滤设置和摘要(汇总)
  StoreVisualOptions     存储或恢复控件视觉选项(布局)
OptionsMenu       选项菜单
  EnableColumnMenu     允许列头上的菜单
  EnableFooterMenu     允许页脚上的菜单
  EnableGroupPanelMenu     允许分组面板上的菜单
OptionsNavigation       导航选项
  AutoFocusNewRow     增加新记录时自动将焦点移动相应的行
  AutoMoveRowFocus     当前焦点在一行的第一个或最后一个单元格时,使用水平导航键可以将焦点移到下一行或上一行
  EnterMoveNextColumn     回车键能移动单元格的焦点
  UseAdvHorzNavigation     使用高级水平导航器(AdvBandedGridView专有属性)
  UseAdvVertNavigation     使用高级垂直导航器(AdvBandedGridView专有属性)
  UseTabKey     使用TAB/SHIFT+TAB移动焦点
OptionsPrint       打印选项
  AutoWidth     根据纸的宽度自动设置视图的列宽
  EnableAppearanceEvenRow     允许偶数行应用界面设置(GridViewPrintAppearances)
  EnableAppearanceOddRow     允许奇数行应用界面设置(GridViewPrintAppearances)
  ExpandAllDetails     打印时所有主行都展开
  ExpandAllGroups     打印时所有分组的行都展开
  PrintBandHeader     打印带的头
  PrintDetails     打印明细
  PrintFilterInfo     打印过滤面板
  PrintFooter     打印页脚
  PrintGroupFooter     打印分组的页脚
  PrintHeader     打印列头
  PrintHorzLines     打印水平的网络线
  PrintPreview     打印预览的部分
  PrintVertLines     打印垂直的网络线
  UsePrintStyles     打印正在使用的界面
OptionsSelection       选择选项
  EnableAppearanceFocusedCell     允许获得焦点的单格使用外观
  EnableAppearanceFocusedRow     允许获得焦点的行使用外观
  EnableAppearanceHideSelection     允许在控件失去焦点时,外观设置应用到选择的行上
  InvertSelection     设置焦点的风格应用到获得焦点的单元格,还是获得焦点的那一行的所有单元格
  MuiltiSelect     允许多选行
  MuiltiSelectMode     多选模式(多选行或多选单元格)(GridView和BandedGridView专有属性)
  UseIndicatorForSelection     当处理多选模式时,能否使用行指示面板来进行行的选择
OptionsView       视图选项
  AllowCellMerge     允许相同值的相邻单元格合并(BandedGridView专有属性)
  AutoCalcPreviewLineCount     根据预览的内容自动计算出文本行的数量
  ColumnAutoWidth     自动调整列宽,使所有列的宽度和视图的宽度匹配
  EnableAppearanceEvenRow     允许偶数行应用界面设置(GridViewPrintAppearances)
  EnableAppearanceOddRow     允许奇数行应用界面设置(GridViewPrintAppearances)
  GroupDramMode     分组行的显示模式
  HeaderFilterButtonShowMode     列头上的过滤按钮的显示模式
  NewItemRowPosition     设置新项目行的位置
  RowAutoHeight     每一行自动根据单元格的内容调整高度(GridView专用属性)
  ShowAutoFilterRow     显示自动过滤行
  ShowBands     显示带的面板(BandedGridView和AdvBandedGridView专有属性)
  ShowChildrenInGroupPanel     视图的分组面板是否担当一个新加入的分组面板
  ShowColumnHeaders     显示列头
  ShowDetailButtons     在主行上显示"主—明细"的扩展按钮
  ShowFilterPanelMode     显示过滤面板
  ShowFooter     显示视图的页脚
  ShowGroupedColumns     显示分组列(GridView专用属性)
  ShowGroupPanel     显示分组面板
  ShowHorzLines     显示水平网格线
  ShowIndicator     显示行指示器面板
  ShowPreview     显示预览部分
  ShowPreviewLines     显示预览线
  ShowvertLines     显示垂直网格线
设计        
(Name)       常规属性
GenerateMember       常规属性
Modifiers       常规属性
数据        
(ApplicationSettings)       常规属性
  (PropertyBinding)     常规属性
Tag       常规属性
外观        
Appearance       外观设置
  BandPanel、BandPanelBackground、ColumnFilterButton、ColumnFilterButtonActive、DetailTip、Empty、EvenRow、FilterCloseButton、FilterPanel、FixedLine、FocusedCell、FocusedRow、FooterPanel、GroupButton、GroupFooter、GroupPanel、GroupRow、HeaderPanel、HeaderPanelBackground、HideSelectionRow、Horzline、OddRow、Preview、Row、RowSeparator、SelectedRow、TopNewRow、VertLine     带的面板、带面板的背景、列过滤按钮、正在使用的列过滤按钮……
    BackColor   背景色
    BackColor2   最后一种背景色(背景是梯度色时)
    BorderColor   边框色
    Font   字体
      Name 字体名称
      Size 字体大小
      Unit 字体设置的单位
      Bold 是否加粗
      GdiCharSet 倾斜字符设置
      Italic 是否斜体
      Strikeout 删除线
      Underline 是否加下划线
    ForeColor   前景色
    GradientMode   背景梯度模式
    Image   背景图片
    Options   界面选项
      UseBackColor 使用显示对象的背景色
      UseBorderColor 使用显示对象的边框色
      UseFont 使用显示对象的字体
      UseForeColor 使用显示对象的前景色
      UseImage 使用显示对象的背景图片
      UseTextOptions 使用显示对象的文本选项(见TextOptions属性)
    TextOptions   文本选项
      Halighment 文本的水平对齐方式
      HotkeyPrefix 热键前缀的是否显示
      Trimming 文本的整理方式
      Valignment 文本的垂直对齐方式
      WordWrap 是否换行
AppearancePrint       打印时的外观设置
  BandPanel、EvenRow、FilterPanel、FooterPanel、GroupFooter、GroupRow、HeaderPanel、Lines、OddRow、Preview、Row     带的面板、偶数行、过滤面板……
    BackColor   背景色
    BackColor2   最后一种背景色(背景是梯度色时)
    BorderColor   边框色
    Font   字体
      Name 字体名称
      Size 字体大小
      Unit 字体设置的单位
      Bold 是否加粗
      GdiCharSet 倾斜字符设置
      Italic 是否斜体
      Strikeout 删除线
      Underline 是否加下划线
    ForeColor   前景色
    GradientMode   背景梯度模式
    Image   背景图片
    Options   界面选项
      UseBackColor 使用显示对象的背景色
      UseBorderColor 使用显示对象的边框色
      UseFont 使用显示对象的字体
      UseForeColor 使用显示对象的前景色
      UseImage 使用显示对象的背景图片
      UseTextOptions 使用显示对象的文本选项(见TextOptions属性)
    TextOptions   文本选项
      Halighment 文本的水平对齐方式
      HotkeyPrefix 热键前缀的是否显示
      Trimming 文本的整理方式
      Valignment 文本的垂直对齐方式
      WordWrap 是否换行
BandPanelRowHeight       带面板的行高(BandedGridView和AdvBandedGridView专有属性)
BorderStyle       当前视图的边框样式
ChildGridLevelName       在加入分组面板中显示的正在分组状态子级别的名字?
ColumnPanelRowHeight       列头高度
DetailHeight       详细视图的视图高度
DetailTabHeaderLocation       设置明细部分中明细分页的显示位置
FixedLineWidth       固定面板分隔器的宽度
FocusRectStyle       焦点框的样式
FooterPanelHeight       视图页脚的高度
GroupFooterShowMode       分组页脚的显示模式
GroupFormat       分组行的格式
GroupPanelText       分组面板中的文本
GroupRowHeight       分组行的高度
Images       图片集
IndicatorWidth       行指示面板的宽度
LevelIndent       分组行和相邻分组级别的缩进
MinBandPanelRowCount       行中最小带头面板的高度(BandedGridView和AdvBandedGridView专有属性)
NewItemRowText       新项目行中显示的文本
PaintStyleName       当前视图的着色样式的名字
PreviewFieldName       预览部分中要显示值的域名
PreviewIndent       预览文本的水平偏移量
PreviewLineCount       预览部分的文本的行数
RowHeight       数据行中单元格的高度
RowSepartatorHeight       行间距
ShowButtonMode       编辑器按钮的显示模式
VertScrollTipFieldName       垂直滚动条上的提示
ViewCaption       视图的标题
行为        
ActiveFilterEnabled       允许使用过滤功能
BestFitMaxRowCount       数据被处理后最合适列的数据行数
DefaultRelationIndex       处理时省缺使用的明细级别
HorzScrollStep       水平滚动条的位移量
HorzScrollVisibilly       水平滚动条的出现设置
ScrollStyle       滚动条的样式
SynchronizeClones       是否克隆视图(通过视图克隆,使外观和数据的表现设置同步)
VertScrollVisibility       显示垂直滚动条

 

 

  

第三方控件使用大全

【张杰章开发过程中整理】

 

一、              ComboBoxEdit

1、 如何使其不可编辑

TextEditStyle 设置为:DisableTextEditor

2、 如何设置鼠标为手形

Cursor 设置为:Hand

二、              GridControl

1、 如何解决单击记录整行选中的问题

View->OptionsBehavior->EditorShowMode 设置为:Click

2、 如何新增一条记录

(1)gridView.AddNewRow()

(2)、实现gridView_InitNewRow事件

3、如何解决GridControl记录能获取而没有显示出来的问题

   gridView.populateColumns();

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

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

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

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

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

6、如何隐藏GridControlGroupPanel表头

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

7、如何禁用GridControl中列头的过滤器

   过滤器如下图所示:

  

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

8、如何在查询得到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;

10、如何定位到第一条数据/记录?

   设置 this.gridView.MoveFirst()

11、如何定位到下一条数据/记录?

   设置 this.gridView.MoveNext()

12、如何定位到最后一条数据/记录?

   设置 this.gridView.MoveLast()

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

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

          this.gridView1.OptionsBehavior.Editable = false;

     this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;

14、如何显示行号?

   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();

            }

   }

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

    设置gridView1.OptionsCustomization.AllowColumnMoving = false;

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

    设置gridView1.OptionsCustomization.AllowSort = false;

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

    设置gridView1.OptionsCustomization.AllowColumnResizing = false;

18

 

19

 

20

 

21

 

22

 

23

 

24

 

25

 

26

 

 

 

三、navBarControl

1、如何在每一个navBarGroup里添加自己想要的控件

   设置GroupStyle: ControlContainer

2、如何设置navBarGroup有滚动条

   设置SkinExplorerBarViewScrollStyle:ScrollBar

3、 如休把navBarGroup设置成如下样式

如图所示:

   设置navBarGroupPaintStyleName属性为: SkinNavigationPane

 

四、toolTipController

效果图如下:

1、如何设置显示的时间长短

   设置this.toolTipController1.AutoPopDelay = 2000;

2如何在屏幕上显示如上图所示的效果

           ToolTipControllerShowEventArgs args = this.toolTipController1.CreateShowArgs();

           this.toolTipController1.SetToolTip(this.sbtnYes, "请选择一条记录!");

           this.toolTipController1.SetTitle(this.sbtnYes, "提示");

           this.toolTipController1.SetToolTipIconType(this.sbtnYes, DevExpress.Utils.ToolTipIconType.Exclamation);

           this.toolTipController1.ShowBeak = true;

           this.toolTipController1.ShowShadow = true;

           this.toolTipController1.Rounded = true;

           this.toolTipController1.ShowHint("请选择一条记录!", "提示");                   

           args.ToolTip = "请选择一条记录!";

   args.Title = "提示";     

3如何设置边框的颜色

   this.toolTipController1.Appearance.BorderColor = Color.Red;

五、TextEdit

1、如何设置TextEdit为多行,可拉伸

   设置TextEdit的Propertity->AutoHeight为:False

 

六、LayoutControl

        1、如何设置LayoutItem为隐藏

           设置LayoutItem.Visibility = Never

      

七、TreeList

1、如何隐藏TreeList的列头

   设置TreeListrOptionsViewShowColumns属性为:False

2、如何

      

八、PictureEdit

1、如何禁止PictureEdit的右键菜单?

设置PictureEditProperties->ShowMenu为:false

 

九、TreeList

1、 如何让TreeList的每个结点高亮显示?

效果如下:

代码如下:

private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)

        {

            TreeList node = sender as TreeList;

            if (e.Node == node.FocusedNode)

            {

                e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);

                Rectangle r = new Rectangle(e.EditViewInfo.ContentRect.Left,

                                            e.EditViewInfo.ContentRect.Top,

                                            Convert.ToInt32(e.Graphics.MeasureString(e.CellText,                                                                treeList1.Font).Width + 1),

                                            Convert.ToInt32(e.Graphics.MeasureString(e.CellText,treeList1.Font).Height));

 

                e.Graphics.FillRectangle(SystemBrushes.Highlight, r);

                e.Graphics.DrawString(e.CellText, treeList1.Font, SystemBrushes.HighlightText, r);

 

                e.Handled = true;

            }

        }

 

//============================================================================

//===============================以下内容为收集===============================

//============================================================================

 

一、改变grid的样式。

DevExpress.XtraGrid.Design.XAppearances xapp;

xapp=new DevExpress.XtraGrid.Design.XAppearances(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\DevExpress.XtraGrid.Appearances.xml ");

 

xapp.LoadScheme(样式名字, gridControl1.MainView);

 

二、选择单元设置和取所选的值

     gridView1.OptionsSelection.MultiSelect = ceMultiSelect.Checked; //多行选择

 

     gridView1.OptionsSelection.MultiSelectMode= GridMultiSelectMode.CellSelect;

     gridView1.OptionsSelection.MultiSelectMode= GridMultiSelectMode. RowSelect; //

三、gridview的控制

///<取当前选中的值>

 

        string GetSelectedRows(GridView view) {

            string ret = "";

            int rowIndex = -1;

            if(view.OptionsSelection.MultiSelectMode == GridMultiSelectMode.RowSelect) {

                foreach(int i in gridView1.GetSelectedRows()) {

                    DataRow row = gridView1.GetDataRow(i);

                    if(ret != "") ret += "\r\n";

                    ret += string.Format("Company Name: {0} (#{1})", row["CompanyName"], i);

                }

            }

            else {

                foreach(GridCell cell in view.GetSelectedCells()) {

                    if(rowIndex != cell.RowHandle) {

                        if(ret != "") ret += "\r\n";

                        ret += string.Format("Row: #{0}", cell.RowHandle);

                    }

                    ret += "\r\n    " + view.GetRowCellDisplayText(cell.RowHandle, cell.Column);

                    rowIndex = cell.RowHandle;

                }

            }

            return ret;

        }

 

 

 

 

 

 

///<设置选中的颜色>//半透明的效果

 private void icbTranslucentColors_CheckedChanged(object sender, System.EventArgs e) {

            if(icbTranslucentColors.Checked) {

                gridView1.Appearance.SelectedRow.BackColor = Color.FromArgb(30, 0, 0, 240);

                gridView1.Appearance.FocusedRow.BackColor = Color.FromArgb(60, 0, 0, 240);

            }

            else {

                gridView1.Appearance.SelectedRow.Reset();

                gridView1.Appearance.FocusedRow.Reset();

            }

        }

 

///<自动添加一行>

gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom//Top/None;

///<设置gridView的按钮>

    gridView1.ShowButtonMode = ShowButtonModeEnum.。。。。。。

      gridView1.OptionsBehavior.Editable = chEdit.Checked; //设置按钮是否可用

///向选中的空间输入字符串

 SendKeys.Send(fsfds);

///控件焦点

gridControl1.Focus();

 

 

 

四、cardView的设置

///是否现实快捷按钮CustomizeButton

cardView1.OptionsView.ShowQuickCustomizeButton=true/false;

///设置CustomizeButton的能否排序和过滤

foreach(GridColumn col in cardView1.Columns)

            {   col.OptionsColumn.AllowSort}

foreach(GridColumn col in cardView1.Columns)

              { col.OptionsFilter.AllowFilter}

 

///card的头上的ico显示

cardView1.LayoutChanged();

///card的头上的标题改变显示

cardView1.CardCaptionFormat =””;

///cardview显示的单个记录的折叠按钮

cardView1.OptionsView.ShowCardExpandButton=true;

 

///

cardView1.MaximumCardColumns =iSize

cardView1.MaximumCardRows = val;

cardView1.OptionsBehavior.AutoHorzWidth

 

///多选

cardView1.OptionsSelection.MultiSelect = ceMultiSelect.Checked;

 

foreach(int i in cardView1.GetSelectedRows()) {

                DataRow row = cardView1.GetDataRow(i);

                if(ret != "") ret += "\r\n";

                ret += string.Format("{0} / {1} : {2:$#,0.00}", row["Trademark"], row["Model"], row["Price"]);

            }///查看选择中的记录

 

CellMerging(单元格合并的效果)

///

CellMerging(单元格合并的效果)

 

gridView1.OptionsView.AllowCellMerge = ceMerging.Checked;

 

Fixed Bands(bandedGridView)

///两边固定

gridBand3 的一列的Fixed属性改成 Right,Left,None

///固定与非固定列之间的距离用

bandedGridView2.FixedLineWidth = (int)numFixedLineWidth.Value;

///设置列的颜色

l          打开Run Designer 选中Columns 选中要改变的列 里面有AppearanceCell (设置列的外观)和 AppearanceHeader(设置表格头的外观)

l          或者选中该列查看“属性”里面也有这两个属性。

///统计 gridView bandedGridView通用)

分组统计和全部统计:

全部统计:在最下面显示统计的结果。

        Run Designer->Total Summary //->General 设置显示        

                                    //->Columns 对特定列来设置统计

 

汇总结果是否显示:可以通过gridControl的view的ShowFooter属性来设置表格下面的汇总结果

分组统计:

以上就是“分组”的 显示在每个分组下面来显示汇总结果。

 

通过bandedGridView2.GroupFooterShowMode= GroupFooterShowMode.。。。。设置分组的显示模式。

///GridView设置菜单

         #region Grid events

         private void gridView1_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs e) {

              if(e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column) {

                   DevExpress.XtraGrid.Menu.GridViewColumnMenu menu = e.Menu as DevExpress.XtraGrid.Menu.GridViewColumnMenu;

                   menu.Items.Clear();

                   if(menu.Column != null) {

                       menu.Items.Add(CreateCheckItem("Not Fixed", menu.Column, FixedStyle.None, imageList2.Images[0]));

                       menu.Items.Add(CreateCheckItem("Fixed Left", menu.Column, FixedStyle.Left, imageList2.Images[1]));

                       menu.Items.Add(CreateCheckItem("Fixed Right", menu.Column, FixedStyle.Right, imageList2.Images[2]));

                   }

              }

         }

         #endregion

         #region New column menu

         DXMenuCheckItem CreateCheckItem(string caption, GridColumn column, FixedStyle style, Image image) {

              DXMenuCheckItem item = new DXMenuCheckItem(caption, column.Fixed == style, image, new EventHandler(OnFixedClick));

              item.Tag = new MenuInfo(column, style);

              return item;

         }

         void OnFixedClick(object sender, EventArgs e) {

              DXMenuItem item = sender as DXMenuItem;

              MenuInfo info = item.Tag as MenuInfo;

              if(info == null) return;

              info.Column.Fixed = info.Style;

         }

         class MenuInfo {

              public MenuInfo(GridColumn column, FixedStyle style) {

                   this.Column = column;

                   this.Style = style;

              }

              public FixedStyle Style;

              public GridColumn Column;

         }

#endregion

 

 

///gridview cardView自动行高

l          行高自动匹配

 gridView1.OptionsView.RowAutoHeight = ce.Checked;

 cardView1.OptionsBehavior.FieldAutoHeight = ce.Checked;

l          当文字多的时候(行高自动匹配 设置是才有用)

     repositoryItemMemoEdit1.LinesCount = ce.Checked ? 0 : 1;

     设置自动全部显示该的所有行。

l          图片时(行高自动匹配 设置是才有用)

     repositoryItemPictureEdit1.CustomHeight = ce.Checked ? 0 : 40;

 

 

///BandedGridView自己订制列的方法

advBandedGridView1.ColumnsCustomization();

advBandedGridView1.DestroyCustomization();

 

advBandedGridView1.OptionsCustomization.AllowChangeColumnParent = edit.Checked;

advBandedGridView1.OptionsCustomization.AllowChangeBandParent = edit.Checked;

advBandedGridView1.OptionsCustomization.ShowBandsInCustomizationForm = edit.Checked;

///设置 图片动画模式

gridView1.OptionsView.AnimationType = (GridAnimationType)

 

///根据字段来分组模式

switch(index) {

                       case 0:

                            SetInterval(gridColumn1, ColumnGroupInterval.Alphabetical);

                            gridColumn2.GroupInterval = ColumnGroupInterval.Alphabetical;

                            break;

                       case 1:

                            SetInterval(gridColumn5, ColumnGroupInterval.DateMonth);

                            break;

                       case 2:

                            SetInterval(gridColumn5, ColumnGroupInterval.DateYear);

                            break;

                       case 3:

                            SetInterval(gridColumn5, ColumnGroupInterval.DateRange);

                            break;

                       case 4:

                            SetSortMode(gridColumn4, ColumnSortMode.Custom);

                            break;

                       default:

                            SetInterval(gridColumn2, ColumnGroupInterval.Value);

                            break;

                                          }

 

     void SetInterval(GridColumn column, ColumnGroupInterval interval) {

              column.GroupInterval = interval;

              column.GroupIndex = 0;

         }

        

         void SetSortMode(GridColumn column, ColumnSortMode sortMode) {

              column.SortMode = sortMode;

              column.GroupIndex = 0;

         }

改变分组样式

gridView1.OptionsView.GroupDrawMode = (GroupDrawMode)

 

///清除分组

gridView1.ClearGrouping(); 

foreach(GridColumn column in gridView1.Columns) {

                       column.GroupInterval = ColumnGroupInterval.Default;

                       column.SortMode = ColumnSortMode.Default;

                                          }

///CustomDataSummaries设置Grop

private void numCustom_ValueChanged(object sender, System.EventArgs e) {

            CustomGridView.UpdateSummary();

            UpdateCaptions(numCustom.Value);

        }

        private void UpdateCaptions(decimal d) {

            CustomGridView.GroupSummary[0].DisplayFormat = "(Order Count [WHERE Freight >= " + d.ToString() + "] = {0})";

            OnSetCaption("");

            gridView2.FormatConditions[0].Value1 = d;

        }

        protected override void OnSetCaption(string fCaption) {

            fCaption = "count records WHERE Freight >= " + numCustom.Value.ToString();

            if(Caption != null)

                Caption.Text = string.Format("{0} ({1})", TutorialName, fCaption);

        }

///下面的效果的实现

 

Run Designere -> Style Conditions ->Add ->column设置列的 Condition设置条件 value1,value2是参数值

 

代码:

   public void setStyle(GridView gridView)

        {

            StyleFormatCondition cn;

 

            cn = new StyleFormatCondition(FormatConditionEnum.Equal, gridView.Columns["bd_c"], null,false);

            cn.ApplyToRow = true;//false只对列其作用。

            cn.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);

            cn.Appearance.ForeColor = Color.Brown;

            gridView.FormatConditions.Add(cn);

        }

 

///LayoutView

 

 

layoutView1.OptionsCarouselMode.PitchAngle = (float)(((int)flatFactor.EditValue) / 360.0f * 2 * Math.PI);///卡片的高度设置flatFactor.EditValue的值(0-360)

layoutView1.OptionsCarouselMode.RollAngle = (float)(((int)rollAngle.EditValue) / 360.0f * 2 * Math.PI);// ///卡片的旋转角度设置rollAngle.EditValue的值(0-360)

layoutView1.OptionsCarouselMode.BottomCardScale = ((int)endSizeScale.EditValue) / 100.0f;

 ///卡片的距离设置endSizeScale.EditValue的值(0-100)

layoutView1.OptionsCarouselMode.BottomCardAlphaLevel = ((int)endAlpha.EditValue) / 100.0f;

///卡片的卡片透明程度设置endAlpha.EditValue的值(0-100)

 layoutView1.OptionsCarouselMode.BottomCardFading = ((int)bottomCardFading.EditValue) / 100.0f; ///卡片的卡片褪色程度设置bottomCardFading.EditValue的值(0-100)

layoutView1.OptionsCarouselMode.CardCount = (int)cardsCount.EditValue;

///卡片的能显示数量设置cardsCount.EditValue的值(0-20)

layoutView1.OptionsCarouselMode.InterpolationMode = (InterpolationMode)

//修改卡片的方式

 

///layout卡片的样式在 run designer -> layout里面设置

 

 Size originalCardMinSize = Size.Empty;

        private void zoomTrackBarControl1_EditValueChanged(object sender, EventArgs e) {

            if(originalCardMinSize == Size.Empty) originalCardMinSize = layoutView1.CardMinSize;

            double koeff = ((int)zoomTrackBarControl1.EditValue) / 100.0 - 0.2;

            Size newSize = new Size(originalCardMinSize.Width + (int)(originalCardMinSize.Width * koeff), originalCardMinSize.Height + (int)(originalCardMinSize.Height * koeff));

            layoutView1.CardMinSize = newSize;

        }////设置卡片的大小的(zoomTrackBarControl1z(0-100))

 

下图中设置layoutView位置的方法

 protected void SetMasterTableLeftPlacement() {

            LayoutItemDragController dc = new LayoutItemDragController(masterTableItem, detailTableItem, InsertLocation.Before, LayoutType.Horizontal);

            DoDragItem(dc);

            SetMasterViewColumnLayout();

        }

        protected void SetMasterTableRightPlacement() {

            LayoutItemDragController dc = new LayoutItemDragController(masterTableItem, detailTableItem, InsertLocation.After, LayoutType.Horizontal);

            DoDragItem(dc);

            SetMasterViewColumnLayout();

        }

        private void SetMasterTableTopPlacement() {

            LayoutItemDragController dc = new LayoutItemDragController(masterTableItem, detailTableItem, InsertLocation.Before, LayoutType.Vertical);

            DoDragItem(dc);

            SetMasterViewRowLayout();

        }

        protected void SetMasterTableBottomPlacement() {

            LayoutItemDragController dc = new LayoutItemDragController(masterTableItem, detailTableItem, InsertLocation.After, LayoutType.Vertical);

            DoDragItem(dc);

            SetMasterViewRowLayout();

        }

        protected void DoDragItem(LayoutItemDragController dc) {

            masterTableItem.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Default;

            masterTableItem.Move(dc);

        }

        protected void SetMasterViewColumnLayout() {

            SetMasterItemVerticalSize();

            employesLayoutView.OptionsBehavior.AllowSwitchViewModes = true;

            employesLayoutView.OptionsView.ViewMode = LayoutViewMode.Column;

            employesLayoutView.OptionsBehavior.AllowSwitchViewModes = false;

            employesLayoutView.Refresh();

        }

        protected void SetMasterViewRowLayout() {

            SetMasterItemHorizontalSize();

            employesLayoutView.OptionsBehavior.AllowSwitchViewModes = true;

            employesLayoutView.OptionsView.ViewMode = LayoutViewMode.Row;

            employesLayoutView.OptionsBehavior.AllowSwitchViewModes = false;

            employesLayoutView.Refresh();

        }//// private DevExpress.XtraLayout.LayoutControlItem masterTableItem;

       

 

///直接打印gridcontrol

Cursor currentCursor = Cursor.Current;

Cursor.Current = Cursors.WaitCursor; //取当前的鼠标。并设置

if(DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable)

DevExpress.XtraPrinting.PrintHelper.ShowPreview(gridControl1);///打印

else

MessageBox.Show("XtraPrinting Library is not found...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

Cursor.Current = currentCursor;

 

 

 /Files/pan11jing/第三方控件DevExpress.rar

 

 

 

 

 

posted @ 2010-01-04 16:06  左少白  阅读(15333)  评论(1编辑  收藏  举报