dev gridcontrol (一)绑定值

 

Dev组件包功能强大,但说明性的文档太少也给我们使用带来的很大的障碍。最近项目需要使用Dev控件,把点点滴滴记录在这里备忘。

1,适当调整列宽(当列很多时)

   gridView1.OptionsView.ColumnAutoWidth= false;

   gridView1. BestFitColumns();

2,多选

    gridView1 .OptionsSelection.MultiSelect = true;

   gridView1 .OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;

3,添加复选框列

  添加一列,FieldName为 "check",将ColumnEdit 设置为 复选框 样式。

  将要绑定的DataTable添加列 "check",Type 为 bool。

  绑定DataTable到GridControl。

  获取: string value = gridview.GetDataRow(i)["check"].toString();

         value == "true" ||  "" ("false")

4,GroupPanel设置

gridView1.GroupPanelText="title";

gridView1.OptionsView.ShowGroupPanel=false;

 

 

gridView1.OptionsView.ShowGroupPanel = false;

取消显示头部的pannel

 gridView1.OptionsView.EnableAppearanceOddRow = true;

奇偶显示

 

 选中变色

  gridView2.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue;

设成只读

1. gridView1.OptionsBehavior.Editable = false;

2. gridView1.Columns[5].readonly= true;

 

左边表头去掉

gridView1.Options.OptionView .ShowIndicator=False;



 

--------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

取值1.

private void gridControl1_DoubleClick(object sender, System.EventArgs e)
        {
            //双击弹出异常日志描述
            if (this.gridView1.RowCount > 0)
            {
                int[] a=this.gridView1.GetSelectedRows();
                string str_GUID=this.gridView1.GetRowCellValue(a[0],"Ex_No").ToString();//获得异常编号
                MessageBox.Show(str_GUID);
                frmExceptionLogDesc dlg=new frmExceptionLogDesc();
                dlg.Text = "异常日志查看";
                dlg.ShowDialog();
            }
        }

 

 取值2.

 

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {

           // DB.Help.UserInfo model = (sender as DevExpress.XtraGrid.GridControl).DataSource as DB.Help.UserInfo;
            if (this.gridView1.RowCount > 0)
            {

                int[] selectRow = this.gridView1.GetSelectedRows();

                DB.Help.UserInfo model = gridView1.GetRow(selectRow[0]) as DB.Help.UserInfo;
              //  string UserName = this.gridView1.GetRowCellValue(selectRow[0], "UserName").ToString();//获得异常编号

                UserInfo ui = new UserInfo();
                ui.UserInfoModel = model;
                ui.Show();
            
            }
        }

 

 补充:

 


(6)barManager的具体设置
在增加了barManager控件以后,在[Click Here to add MainMenu] [Click Here to Tool Bar]里面选择[Click Here to Tool Bar] 填写需要新增的工具栏按钮。
进入Designer 里面,选择ToolBars  ->Custom 1->OptionsBar 里面进行如下设置:
AllowQuickCustomization=false
DrawDragBorder=false
RotateWhenVertical=false
UseWholeRow=True
以上4项进行初始化设置

(7) 在DataGrid 里面增加状态栏
首先在BarManager里面增加StaticText  把新增的barStaticItem 的AutoSize 设置为Spring
然后,编写以下代码:


private void StateCote()
        {
          
            if (gridView1.RowCount!=0)
            {
                int a=this.gridView1.RowCount;
                barStaticItem1.Caption="当前共有记录:"+a.ToString();
                int[] b=this.gridView1.GetSelectedRows();
                b[0]+=1;
                barStaticItem2.Caption="当前选中:"+b[0].ToString();
            }
            else
            {
                barStaticItem1.Caption="当前共有记录:";
                barStaticItem2.Caption="当前选中:";
            }       
        }

        private void gridControl1_Click(object sender, System.EventArgs e)
        {
            StateCote();
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            StateCote();
        }

(8) DateTable 填充DataGrid
这里需要引用:


using DevExpress.Utils;



/**//// <summary>
        /// 根据DataTable 填充DataGrid
        /// </summary>
        /// <param name="dt"></param>
        private void DisposeDataGrid(DataTable dt)
        {
            //标题居中
            gridView1.Appearance.HeaderPanel.TextOptions.HAlignment =HorzAlignment.Center;
           
            this.gridControl1.DataSource = dt;
            gridView1.Columns[0].Visible = false;//异常日志GUID
            gridView1.Columns[1].Visible = false;//通行编号
            gridView1.Columns[2].Visible = false;//通道编号
           
            gridView1.Columns[3].Caption = "通道名称";
            gridView1.Columns[3].Width = 100;

            gridView1.Columns[4].Caption = "卡号";
            gridView1.Columns[4].Width = 100;

            gridView1.Columns[5].Caption = "持卡人姓名";
            gridView1.Columns[5].Width = 60;


            gridView1.Columns[6].Caption = "主卡卡号";
            gridView1.Columns[6].Width = 100;
           
            gridView1.Columns[7].Caption = "主卡持卡人";
            gridView1.Columns[7].Width = 60;
           
            gridView1.Columns[8].Caption = "通行时间";
            gridView1.Columns[8].Width = 100;


            gridView1.Columns[9].Caption = "车牌号码";
            gridView1.Columns[9].Width = 60;
           
           
           
            gridView1.Columns[10].Visible = false;//图象GUID


            gridView1.Columns[11].Caption = "异常描述";
            gridView1.Columns[11].Width = 100;

            gridView1.Columns[12].Caption = "处理结果";
            gridView1.Columns[12].Width = 100;

            gridView1.Columns[13].Visible = false;//ImageID


            //可以排序
            gridView1.OptionsCustomization.AllowSort=true;
        }
其中有一列显示时间类型

            gridView1.Columns[3].Caption = "操作时间";
            gridView1.Columns[3].Width = 200;
            gridView1.Columns[3].UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
            gridView1.Columns[3].DisplayFormat.FormatString = "F";
            gridView1.Columns[3].DisplayFormat.FormatType = FormatType.DateTime;

 

posted @ 2012-08-01 14:53  咸鱼公子  Views(4581)  Comments(1Edit  收藏  举报