首页 > 其他分享 >dev常见操作from宋

dev常见操作from宋

时间:2023-01-10 13:45:57浏览次数:37  
标签:false gdv point DevExpress 常见 dev 设置 gridView1 操作

DEV控件在工具箱中消失处理方法

开始-->程序-->Developer Express v2009 vol 3(依据版本不同)-->Components-->Tools-->ToolboxCreator

 

1、点击一行选择完整一行

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

Run Designer->View->OptionsSelection.EnableAppearanceFocusedCell = false;

2、设置行不可编辑

Run Designer->View->OptionsBehavior->Editable 设置为:false

但这样也无法拷贝数据了,最好是上面Editable保持true,设置:

Run Designer->View->OptionsBehavior->ReadOnly 设置为:true

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

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

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

4、隐藏GridControlGroupPanel表头

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

取消压缩表格在窗体内完整显示(不出现横向滚动条)

Run Design->OptionsView->OptionsView.ColumnAutoWidth = false;

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

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

OptionsView->ShowAutoFilterRow:true 显示顶端过滤行

6、如何在行头部显示行号?

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

7、得到当前选定记录某字段的值

sValue= gridView1.GetDataRow(gridView1.FocusedRowHandle)[FieldName].ToString();

8、不显示MasterDetailView

gridView1.OptionsDetail.EnableMasterViewMode=false;

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、得到/设置单元格数据

string ss=gridView1.GetRowCellDisplayText(0,gridView1.Columns[0]);

string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);

13、设置列宽自动适应文字长短

gridView1.BestFitColumns();

gridView1.BestFitMaxRowCount = 500; //对行数过多时,避免调整时间过长,根据前多少行来判断每列最佳宽度

14、设置gridview控件的字体

designer-views-外观-appearance-row-font中设置

15、隐藏行头列

gdv_point.OptionsView.ShowIndicator = false; //取消行头列

16、更改某一行的颜色,添加事件

private void gdv_point_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)

{          

     DataRow dr = gdv_point.GetDataRow(e.RowHandle);

     if (dr != null && e.RowHandle==2)

           e.Appearance.ForeColor = Color.Red; //因为前面已设置了奇偶行背景色,所以这里如果再设置某行背景色无效              

}

17、更改某一单元格颜色,添加事件

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

{

    if (e.RowHandle == 4 && e.Column.AbsoluteIndex == 4) //e.Column.FieldName == "FIR";

       e.Appearance.ForeColor = Color.Green;

}

18、获取或设置某一单元格文字

DataRow dr = gdv_point.GetDataRow(gdv_point.FocusedRowHandle); //与DataTable的一样

dr[3] = "456";

 

19、设置奇偶行颜色后就不能再更改某行的背景色,解决方法,不设奇偶色,在RowStyle事件中绘制,同时设置某行颜色

private void gdv_point_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)

        {

            if (e.RowHandle < 0) return; //还未加载数据           

            if (e.RowHandle % 2 == 0)

                e.Appearance.BackColor = Color.FromArgb(255, 255, 240); // 设置偶数行颜色

            else

                e.Appearance.BackColor = Color.FromArgb(255, 255, 255);  // 设置奇数行颜色默认也是白色 可以省略            

           

            if (gdv_point.GetDataRow(e.RowHandle)["当前状态"].ToString().Trim() != "")

                e.Appearance.BackColor = Color.FromArgb(255, 0, 0);           

         

        }

 

20、设置某行为顶端第一显示行,即视图滚动到指定行:TopRowIndex(没有下面的方法好)

int oldtop = parentFrm.gdv_point.TopRowIndex;//获取原来的最顶行

int oldfocusrow = parentFrm.gdv_point.FocusedRowHandle;

parentFrm.butquery_Click(null,null);//重新执行查询

parentFrm.gdv_point.TopRowIndex = oldtop;//将最顶行设回原来值,如果原来值超出总行数也不会报错,会将最顶行设为最大可能值。

parentFrm.gdv_point.FocusedRowHandle = oldfocusrow; //超出最大行数也不会报错

 

21、根据某cell的值使界面定位并高亮选择该行。LocateByDisplayText

gdv_point.FocusedRowHandle = gdv_point.LocateByDisplayText(0, gdv_point.Columns["ID"], pid);

 

22、时间类型默认在gridview中只能显示年月日,如果要显示时分秒,需要在RowCellStyle事件中添加

if (e.Column.ColumnType.ToString() == "System.DateTime")

{

      e.Column.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss"; //MM和HH一定要大写

     e.Column.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; //这句必须要

 

      //e.Column.DisplayFormat.FormatString = "{0:N2}"; //数字格式化

      //e.Column.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;

}

23、整个gridview设为可编辑后,使符合某些条件的行或列不可编辑

private void gdv_pdfpnt_ShowingEditor(object sender, CancelEventArgs e)

{

     if (gdv_pdfpnt.FocusedColumn.AbsoluteIndex == 1)

        e.Cancel = true;

}

24、显示自动过滤行

OptionView:ShowAutoFilterRow              显示自动过滤行

25、让输入值自动大写

RepositoryItemTextEdit editor = (RepositoryItemTextEdit)gdc_pdfpnt.RepositoryItems.Add("TextEdit");

editor.CharacterCasing = CharacterCasing.Upper;

gdv_pdfpnt.Columns[3].ColumnEdit = editor;

26更换绑定的DataTable

gdv_pnt.Columns.Clear();

gdc_pnt.DataSource = dt;           

gdv_pnt.RefreshData();

27、多行模式获取所有选择行

List<int> selrows = gdv_apoint.GetSelectedRows().ToList(); //多行选择

 

28 GridControl控件中显示自定义控件的方法//2016.4.16

添加MouseDown事件,与RowCellClick事件的区别在于RowCellClick只能处理可编辑Cell

 

private void gdv_pdfpnt_MouseDown(object sender, MouseEventArgs e)

        {

DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hinfo = gridView1.CalcHitInfo(new Point(e.X, e.Y));

            if (hinfo.InRowCell && e.Button == MouseButtons.Left && e.Clicks == 1)

            {

              

                gridView1.FocusedRowHandle = hinfo.RowHandle;

 

                DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;

                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo viewinfo = view.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo;

 

                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo df = viewinfo.GetGridCellInfo(hinfo);

               

                Rectangle rct = df.Bounds;

                simpleButton1.Bounds = new Rectangle(rct.Left + gridControl1.Left, rct.Top + gridControl1.Top, rct.Width, rct.Height);

 

               

            }

 

            //获取点击cell的位置并显示控件

            GridView view = sender as GridView;

            GridViewInfo viewInfo = view.GetViewInfo() as GridViewInfo;

            GridHitInfo hitInfo = view.CalcHitInfo(e.Location);

            if (hitInfo.InRowCell && hitInfo.Column.AbsoluteIndex == gdv_pdfpnt.Columns.Count - 1 && e.Button == MouseButtons.Left && e.Clicks == 1) //限制鼠标事件为左键单击

            {

                gdv_pdfpnt.FocusedRowHandle = hitInfo.RowHandle; //关键!触发此事件时,dev控件还没来得及将当前行切换到点击行,这里做强制切换,否则会出现混乱。

                               

                GridCellInfo cellInfo = viewInfo.GetGridCellInfo(hitInfo);

                Rectangle rect = cellInfo.Bounds;

 

                int left = gdc_pdfpnt.Left+rect.Left; //rect 只是客户区坐标,要转化为屏幕绝对坐标

                int top = gdc_pdfpnt.Top+rect.Top+3;

 

                uC_TypeSelector.Left = left;

                uC_TypeSelector.Top = top;

                uC_TypeSelector.Visible = true;

 

                string val=gdv_pdfpnt.GetDataRow(hitInfo.RowHandle)[hitInfo.Column.AbsoluteIndex].ToString();

                if (val != "") //设置弹出控件初始值

                    uC_TypeSelector.RefFormValue(val); //将cell值初始化类型选择框,每次改变uc控件值的同时,也会触发控件回调函数往该界面上写回值,所以这里其实还执行了一次界面赋值

                else

                    uC_TypeSelector.RefFormValue("   ");

            }

            else

                uC_TypeSelector.Visible = false;

        }

 

29、自动添加行号的方法:

1、开启显示标记列 gdv_point.OptionsView.ShowIndicator = true;默认就是开的

2、设置标记列列宽

 

3、添加事件

private void gdv_pro_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)

        {

            //e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;

            if (e.Info.IsRowIndicator)

            {

                if (e.RowHandle >= 0)

                {

                    e.Info.DisplayText = (e.RowHandle + 1).ToString();

                }

            }

        }

 

30、添加双击事件添加gdv_pro_MouseDown事件

可以将gdv_point.OptionsBehavior.Editable = false;也可不设置

DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = gdv_pro.CalcHitInfo(new Point(e.X, e.Y));

if (hInfo.InRow && e.Button == MouseButtons.Left && e.Clicks == 2)

 

31、根据界面宽度自动设置列宽模式

在界面或某控件的SizeChang事件中执行此函数

public static void BestFitGridViewColumnsWith( DevExpress.XtraGrid.Views.Grid.GridView gdv )

        {

            //先设置最小列宽

            gdv.BestFitColumns();

 

            //获取所有列总最小宽度

            int tt = 0;

            for (int i = 0; i < gdv.Columns.Count; i++)

                tt += gdv.CalcColumnBestWidth(gdv.Columns[i]);

 

            //如果有指示列,加上其宽度

            if (gdv.OptionsView.ShowIndicator)

                tt += gdv.IndicatorWidth;

           

            //根据宽度调整列显示模式

            if (tt < gdv.ViewRect.Width)

                gdv.OptionsView.ColumnAutoWidth = true;

            else

                gdv.OptionsView.ColumnAutoWidth = false;

        }

32、设置单元格中实现换行

首先,查询语句中用CHR(10)分行符连接显示内容,如:zx_org||CHR(10)||zx_cut 走向

绑定数据后用

DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit x = new DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit();

gdv_zxnotmatch.Columns["走向"].ColumnEdit = x;

gdv_zxnotmatch.OptionsView.RowAutoHeight = true;

可实现分行显示

 

 

设置主表、从表嵌套显示,主表行前出现+号,点击显示满足关联关系的从表数据

1、在主view新添加一级level主,从视图分别为gridView1和gridView2

2、新建Dataset将主视图、从视图对应的两张datatable添加进去,并设置这两张表的公共字段建立关联,即主键和外键

3、将此Dataset的具有主键的Table赋给gridConcrol的DataSource即可

DataSet ds = new DataSet();

var t1 = DBFactorySingleton.GetInstance().Factory.GetDataTable(string.Format(@"select txt_name 名称, code_id 识别,significant_point_id ID from {0}.vor", AisLogical.dbuser)).Copy(); //加copy的原因是原datatable已经属于一个dataset

t1.TableName = "t1"; //如果不对table命名,两次添加的table都会叫默认的表名data,第二张表就添加不进此dataset

ds.Tables.Add(t1); //主表显示内容

 

var t2 = DBFactorySingleton.GetInstance().Factory.GetDataTable(string.Format(@"select significant_point_id ID, geo_lat 纬度,geo_long 经度,val_freq||uom_freq 频率,val_mag_var 磁差  from {0}.vor", AisLogical.dbuser)).Copy();

t2.TableName = "t2";

ds.Tables.Add(t2);//子表显示内容

 

////将子表与主表的公共字段作为主键和外键,目的为了建立关系,由主表带出子表

DataColumn keyColumn = ds.Tables["t1"].Columns["id"];

DataColumn foreignKeyColoumn = ds.Tables["t2"].Columns["id"];

//建立关系, 此关系名称NAIP会默认显示在子表表头,可通过设置主表的OptionsDetail.ShowDetailTabs = false;来隐藏名称

ds.Relations.Add("NAIP", keyColumn, foreignKeyColoumn);

 

gridControl1.DataSource = ds.Tables["t1"]; //将具有主键的datatable赋给整个控件的DataSource完成主、从表绑定

 

////////////////////////////////////////////////

//完全用代码实现Grid控件设置

#region DevGridControl控件设置

            ///////////////////////////////////////////////////////////////////////

            //1添加行号

            //gdv_point.IndicatorWidth = 50; //最好不要显示此列

            //添加事件显示行号

            //private void gdv_point_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)

            //{

            //        if (e.Info.IsRowIndicator && e.RowHandle>=0)

            //            e.Info.DisplayText = (e.RowHandle + 1).ToString();

            //        e.Info.ImageIndex = -1; //不显示小三角

            //}

 

            //2外观设置可设置自带的4种风格,可再做调整

            gdc_point.LookAndFeel.UseDefaultLookAndFeel = false;

            gdc_point.LookAndFeel.SkinName = "Caramel";

            //gdc_point.LookAndFeel.SkinName = "Lilian";

            //gdc_point.LookAndFeel.SkinName = "iMaginary";           

            //gdc_point.LookAndFeel.SkinName = "Money Twins";

            gdv_point.OptionsView.EnableAppearanceOddRow = true;   // 允许设置奇数行

            gdv_point.OptionsView.EnableAppearanceEvenRow = true;   // 允许设置偶数行           

            gdv_point.Appearance.OddRow.BackColor = Color.FromArgb(255, 255, 255);  // 设置奇数行颜色默认也是白色 可以省略            

            gdv_point.Appearance.EvenRow.BackColor = Color.FromArgb(255, 255, 240); // 设置偶数行颜色

            gdv_point.Appearance.Row.Font = new System.Drawing.Font("微软雅黑", 10.5f); //表内字体

            gdv_point.Appearance.HeaderPanel.Font = new System.Drawing.Font("仿宋", 13f, FontStyle.Bold);//表头字体                       

            gdv_point.ColumnPanelRowHeight = 35; //表头面板高度

            gdv_point.RowHeight = 30; //表格行高

            gdv_point.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 240, 151); //选中行背景色

            gdv_point.Appearance.FocusedRow.ForeColor = Color.Black;  //选中行前景色

            gdv_point.Appearance.HideSelectionRow.BackColor = Color.White; //失去焦点是选中行前景色

            gdv_point.Appearance.HideSelectionRow.ForeColor = Color.Black;//失去焦点是选中行背景色

 

            //3、行选模式

            gdv_point.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click; //设置整行选择           

            gdv_point.OptionsBehavior.ReadOnly = true; //不可编辑

            gdv_point.OptionsSelection.EnableAppearanceFocusedCell = false; //取消选中时单元格高亮      

 

            //4、操作

            gdv_point.OptionsMenu.EnableColumnMenu = false; //禁用列名右键弹出菜单

            gdv_point.OptionsMenu.EnableFooterMenu = false;//禁用脚注右键弹出菜单

            gdv_point.OptionsView.ShowGroupPanel = false;//禁用拖表头group面板

            //gdv_point.OptionsCustomization.AllowFilter = false; //禁用列头筛选

            gdv_point.OptionsView.ColumnAutoWidth = false;//禁用自动列宽,恢复横向滚动条

 

            //5、列宽优化

            //每次绑定数据后要执行gdv_point.BestFitColumns(); 来优化每列宽度           

            gdv_point.BestFitMaxRowCount = 500; //根据前多少行来判断每列最佳宽度

            gdv_point.OptionsDetail.ShowDetailTabs = false;//隐藏从表的表头标签

            gdv_point.OptionsView.ShowIndicator = false; //取消行头列

            #endregion

 

标签:false,gdv,point,DevExpress,常见,dev,设置,gridView1,操作
From: https://www.cnblogs.com/adamgq/p/17039918.html

相关文章