DEV控件:gridControl常用属性设置

DEV控件:gridControl常用属性设置,第1张

概述  1.隐藏最上面的GroupPanel   gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值   sValue=Table.Rows[gridView1.FocusedRowHandle][FieldName].ToString(); 3.数据只读   gridView1.OptionsBehavior.Editable=fa  

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="柳生飘絮";

6.设置数据源:
   grIDControl1.DataSource = dt;
   绑定每一列的@R_502_6852@dname--属性
   对于Oracle数据库,所有的在设计器里写的程序中的字段名必须大写,否则可能绑定不上字段,sqlserver没有这个限制.

7.读写拷贝权限设置
  只读不可拷贝:
    ColumnVIEwOptionsBehavior.Editable = False

  只读可拷贝:
    ColumnVIEwOptionsBehavior.Editable = True
    OptionsColumn.AllowEdit = True
    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.设置单元格数据(将0行0列的单元格赋值123)
   grIDVIEw1.SetRowCellValue(0,grIDVIEw1.Columns[0],"123");

 
13.手动添加dev的列
  DevExpress.XtraGrID.Columns.GrIDColumn Col1=new DevExpress.XtraGrID.Columns.GrIDColumn ();
  Col1.FIEldname="FID";
  Col1.Visible=true;
  Col1.VisibleIndex=grIDVIEw1.Columns.Count;
  grIDVIEw1.Columns.Add(Col1);


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.删除: (修改了dgvdel里的datagrIDvIEwdel方法)
    public static voID datagrIDvIEwdel_Dev(DevExpress.XtraGrID.VIEws.GrID.GrIDVIEw Mydgv)
    {
       if (MessageBox.Show("你确定要删除选中的记录吗?","删除提示",MessageBoxbuttons.YesNo,               MessageBoxIcon.Warning,MessageBoxDefaultbutton.button2,false) == DialogResult.Yes)
       {
           int iSelectRowCount = Mydgv.SelectedRowsCount;
           if (iSelectRowCount > 0)
           {
             Mydgv.DeleteSelectedRows();
           }
       }
    }
 
16. 新增: (对于新增,其本身的AddNewRow方法就可以做到)
    private voID btn_add_Click(object sender,EventArgs e)
   
       grIDVIEw1.AddNewRow();  
     }
    具体如果对于新加行还有什么特别的设置,可以在它grIDVIEw1_InitNewRow事件中填写:
    private voID grIDVIEw1_InitNewRow(object sender,DevExpress.XtraGrID.VIEws.GrID.InitNewRowEventArgs e)
    {
       ColumnVIEw VIEw = sender as ColumnVIEw;
       VIEw.SetRowCellValue(e.RowHandle,VIEw.Columns[0],grIDVIEw1.GetRowCellValue(grIDVIEw1.GetRowHandle(grIDVIEw1.RowCount - 2),grIDVIEw1.Columns[0])); //复制最后一行的数据到新行

            VIEw.SetRowCellValue(e.RowHandle,VIEw.Columns[1],grIDVIEw1.Columns[1])); //复制最后一行的数据到新行

    }

 
17. 保存 (第三方控件提供的RefreshData和RefreshDataSource方法对于保存数据都不好使,最后还是使用了Dgvsave的datagrIDvIEwsave方法,用这个方法就可以)


18.特效:grIDcontrol中有5种vIEw 型式,普通的是grIDvIEw,然后分别为cardvIEw、BandedVIEw、Advanced BandedVIEw、LayoutVIEw;共5种。
  1)、vIEw组中把OptionVIEw下的viewmode 设置成“Carousel”就达到这种“旋转木马”式的grIDcontrol vIEw 特效了
  2)、layoutVIEw1.OptionsCarouselMode.PitchAngle 这个属性决定“旋转木马”的pitch angle 螺距角; 螺旋角; 螺旋升角; 俯仰角; 倾角; 节锥半角
  3)、Roll Angle 属性决定着 倾侧角度
  4)、指定数据源,显示数据:
  //显示数据
        private voID showData(List<Employee > List)
        {
            Datatable dt = new Datatable("OneEmployee");
            dt.Columns.Add("Caption",System.Type.GetType("System.String"));
            dt.Columns.Add("Department",System.Type.GetType("System.String"));
            dt.Columns.Add("Photoname",System.Type.GetType("System.Byte[]"));

            for (int i = 0; i < List.Count; i++)
            {
                DaTarow dr = dt.NewRow();
                dr["Caption"] = List[i].name;
                dr["Department"] = List[i].Department;
                string imagePath = @"D:C#photos" + List[i].Photopath;
                dr["Photoname"] = getimageByte(imagePath);
                dt.Rows.Add(dr);
            }
            grIDControl1.DataSource = dt;
        }

        //返回图片的字节流byte[]
        private byte[] getimageByte(string imagePath)
        {
            @R_502_6852@Stream @R_502_6852@s = new @R_502_6852@Stream(imagePath,@R_502_6852@Mode.Open);
            byte[] imgByte = new byte [@R_502_6852@s.Length ];
            @R_502_6852@s.Read(imgByte,imgByte.Length);
            @R_502_6852@s.Close();
            return imgByte;
        }

19.检查数据的有效性
  在grIDvIEw的ValIDateRow事件中加入检查代码:
  #region 检查数据
  private voID grIDVIEw1_ValIDateRow(object sender,ValIDateRowEventArgs e)
  {
  GrIDVIEw vIEw = sender as GrIDVIEw;
  vIEw.ClearColumnErrors();

  if (vIEw.GetRowCellValue(e.RowHandle,"ReceiveDate") == dbnull.Value)
  {
  e.ValID = false;
  vIEw.SetColumnError(vIEw.Columns["ReceiveDate"],"必须指定日期");
  }

  }
  #endregion
  调用grIDvIEw.UpdateCurrentRow()方法执行检查


常用的DevExpress Winform 4个代码片段:

一 、GrIDControl的删除 *** 作

private voID rIlinkEditInfoDel_Click(object sender,EventArgs e)
{
     if (XtraMessageBox.Show("请确定是否删除当前记录?","警告",MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         DaTarow row = gvInfos.GetDaTarow(gvInfos.FocusedRowHandle);
          delByCode(row["Code"].ToString());
         XtraMessageBox.Show(" *** 作成功!");
     }
}

二、绑定非数据表中列

Hashtable ht = new Hashtable();

private voID grIDVIEw6_CustomUnboundColumnData(object sender,DevExpress.XtraGrID.VIEws.Base.CustomColumnDataEventArgs e)
{
     GrIDVIEw VIEw = sender as GrIDVIEw;
     if (e.RowHandle >= 0)
     {
         object neeDalert = VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["neeDalert"]);
         if (neeDalert != null & neeDalert != dbnull.Value && neeDalert.ToString().Trim() != "0" & VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["Value"]) != dbnull.Value)
         {
             decimal AverValue = Convert.ToDecimal(VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["Value"]));
             object MinValue = VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["MinValue"]);
             object MaxVlaue = VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["MaxValue"]);
             if (MinValue != dbnull.Value & MinValue != null & MaxVlaue.ToString() != "" & MaxVlaue != dbnull.Value && MaxVlaue != null & MaxVlaue.ToString() != "")
             {
                 decimal grIDColumn2 = Convert.ToDecimal(VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["MinValue"]));
                 decimal grIDColumn1 = Convert.ToDecimal(VIEw.GetRowCellValue(e.RowHandle,VIEw.Columns["MaxValue"]));
                 if (grIDColumn2 > AverValue || AverValue > grIDColumn1)
                 {
                     if (!ht.ContainsKey("pic"))
                         ht.Add("pic",Getimage(1));
                     e.Value = ht["pic"];
                 }
         

总结

以上是内存溢出为你收集整理的DEV控件:gridControl常用属性设置全部内容,希望文章能够帮你解决DEV控件:gridControl常用属性设置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1179830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存