最新范文 方案 计划 总结 报告 体会 事迹 讲话 倡议书 反思 制度 入党

GridControl控件学习总结

日期:2020-12-11  类别:最新范文  编辑:一流范文网  【下载本文Word版

GridControl控件学习总结 本文关键词:控件,学习,GridControl

GridControl控件学习总结 本文简介:GridControl(基于GridView)总结gridControl设计器设计器中左边导航部分Views是用于设计gridControl的布局,Columns是用于设计gridControl中列,列属性中的Name是指列明,FileName是指对应的数据库字段(实体类、BaseValue)的名称

GridControl控件学习总结 本文内容:

GridControl(基于GridView)总结

gridControl设计器

设计器中左边导航部分Views是用于设计gridControl的布局,Columns是用于设计gridControl中列,列属性中的Name是指列明,FileName是指对应的数据库字段(实体类、BaseValue)的名称,Caption是指定列标题显示文本(类似TextBox中的Text属性)。Appearances是设计控件的外观样式。

注:options(选项)下的属性用于设置页面布局。

gridControl绑定

DevExpress中的控件绑定数据源时,都不需要调用DataBind()方法。

this.gridControl1.DataSource

=

getGoodsInfo.GetGoodsInfoDT(typeId);

注:使用泛型集合绑定数据源,在GridView中实现自动添加行时,AddNewRow()方法不起效。在获取数据行时,GetDataRow()方法报错。如果使用gridcontrol用于只呈现数据可以使用泛型集合作为数据源,如果涉及到增、删、改建议使用DataTable作为数据源,这样以上两个方法可以正常使用。

gridControl实现自动添加行

this.gridView1.AddNewRow();

//only

one

line

code

gridControl获取修改行的数据

gridControl常用函数介绍

GetDataRow()

用于获取指定索引的行。

GetFocusedRowCellValue()

获取鼠标选中行的某列值。

GetRowCellValue()

获取某行某列的值。

关于XtraGrid的使用(GridControl小结)

DevExpress

XtraGrid的使用(AspxGridControl小结)

收藏

自定义焦点行的方法

gridView_bcode.FocusedRowHandle

=

focuseRowInt;

//通过设置GridView

的FocusedRowHandle属性

view

plaincopy

to

clipboardprint?

获取焦点行任意单元格的数据

ColumnView

cv

=

(ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID

否则无法从表头连删获取不到id

int

focusedhandle

=

cv.FocusedRowHandle;

object

rowIdObj

=

gridView1.GetRowCellValue(focusedhandle,“id“);

if

(DBNull.Value

!=

rowIdObj)

{

FocusedRow_id

=

Convert.ToInt32(rowIdObj);

}

获取焦点行任意单元格的数据

ColumnView

cv

=

(ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID

否则无法从表头连删获取不到id

int

focusedhandle

=

cv.FocusedRowHandle;

object

rowIdObj

=

gridView1.GetRowCellValue(focusedhandle,“id“);

if

(DBNull.Value

!=

rowIdObj)

{

FocusedRow_id

=

Convert.ToInt32(rowIdObj);

}

view

plaincopy

to

clipboardprint?

当数据发生变化时执行

private

void

gridView1_CellValueChanged(object

sender,CellValueChangedEventArgs

e)

{

int

intRowHandle

=

e.RowHandle;

FocusedRow_bumen

=

Convert.ToString(gridView1.GetRowCellValue(intRowHandle,“bumen“));

FocusedRow_xingming

=

Convert.ToString(gridView1.GetRowCellValue(intRowHandle,“xingming“));

//FocusedRow_jibengongzi

=

Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle,“jibengongzi“));

object

rowJibengongziObj

=

gridView1.GetRowCellValue(intRowHandle,“jibengongzi“);

if

(DBNull.Value

!=

rowJibengongziObj)

{

FocusedRow_jibengongzi

=

Convert.ToDecimal(rowJibengongziObj);

}

}

当数据发生变化时执行

private

void

gridView1_CellValueChanged(object

sender,CellValueChangedEventArgs

e)

{

int

intRowHandle

=

e.RowHandle;

FocusedRow_bumen

=

Convert.ToString(gridView1.GetRowCellValue(intRowHandle,“bumen“));

FocusedRow_xingming

=

Convert.ToString(gridView1.GetRowCellValue(intRowHandle,“xingming“));

//FocusedRow_jibengongzi

=

Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle,“jibengongzi“));

object

rowJibengongziObj

=

gridView1.GetRowCellValue(intRowHandle,“jibengongzi“);

if

(DBNull.Value

!=

rowJibengongziObj)

{

FocusedRow_jibengongzi

=

Convert.ToDecimal(rowJibengongziObj);

}

}

view

plaincopy

to

clipboardprint?

设置焦点行的焦点单元格的位置

ColumnView

view

=

(ColumnView)gridControl_Gongzi.FocusedView;

view.FocusedColumn

=

view.Columns[“bumen“];

设置焦点行的焦点单元格的位置

ColumnView

view

=

(ColumnView)gridControl_Gongzi.FocusedView;

view.FocusedColumn

=

view.Columns[“bumen“];

view

plaincopy

to

clipboardprint?

当焦点行发生改变时执行

获取选中焦点行id

private

void

gridView1_FocusedRowChanged(object

sender,DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs

e)

{

int

intRowHandle

=

e.FocusedRowHandle;

object

rowIdObj

=

gridView1.GetRowCellValue(intRowHandle,“id“);

if

(DBNull.Value

!=

rowIdObj)//做个判断否则获取不到id后报错

{

FocusedRow_id

=

Convert.ToInt32(rowIdObj);

}

}

当焦点行发生改变时执行

获取选中焦点行id

private

void

gridView1_FocusedRowChanged(object

sender,DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs

e)

{

int

intRowHandle

=

e.FocusedRowHandle;

object

rowIdObj

=

gridView1.GetRowCellValue(intRowHandle,“id“);

if

(DBNull.Value

!=

rowIdObj)//做个判断否则获取不到id后报错

{

FocusedRow_id

=

Convert.ToInt32(rowIdObj);

}

}

view

plaincopy

to

clipboardprint?

焦点行的FocusedHandle

FocuseRow_Handle

=

-999998;

获取焦点行的handle

ColumnView

newview

=

(ColumnView)gridControl_Gongzi.FocusedView;

FocuseRow_Handle

=

newview.FocusedRowHandle;

回车添加新行

private

void

gridView1_KeyPress(object

sender,KeyPressEventArgs

e)

{

if

(e.KeyChar

==

13)

{

ColumnView

view

=

(ColumnView)gridControl_Gongzi.FocusedView;

if(view.IsLastRow)

{

if

(FocuseRow_Handle

==

0)

{

gridView1.AddNewRow();

ColumnView

newview

=

(ColumnView)gridControl_Gongzi.FocusedView;

newview.FocusedColumn

=

newview.Columns[“bumen“];//定位焦点网格的位置

FocuseRow_Handle

=

newview.FocusedRowHandle;//获取新焦点行的

FocuseRowHandle

并初始化全局变量FocuseRow_Handle供保存操作时判断是update还是insert

Gridcontrol的作用笔记

girdView在第一列显示行号

调整第一列的宽度

this.gridView1.IndicatorWidth

=

40;

添加监听事件

this.gridView1.CustomDrawRowIndicator

+=

new

DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.gridView1_CustomDrawRowIndicator);

//在非类里这段代码

private

void

gridView1_CustomDrawRowIndicator(object

sender,DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs

e)

.{

if

(e.Info.IsRowIndicator

}

}

private

void

mnuLoad_Click(object

sender,System.EventArgs

e)

{

//

TODO:

Load

Customers

Database

db

=

null;

db

=

DatabaseFactory.CreateDatabase();

DataSet

ds

=

db.ExecuteDataSet(

CommandType.Text,“SELECT

ID,Name,Age

From

UserInfo“);

gridControl1.DataSource

=

ds.Tables[0];

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

this.gridView1.FocusRectStyle

=

DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;

this.gridView1.OptionsBehavior.Editable

=

false;

this.gridView1.OptionsSelection.EnableAppearanceFocusedCell

=

false;

设置列的标题

gridView1.Columns[0].Caption

=

“编号“;

gridView1.Columns[1].Caption

=

“名称“;

gridView1.Columns[2].Caption

=

“年龄“;

设置列的名称,便于进行分组和Foot的统计等信息显示

gridView1.Columns[0].Name

=

“ID“;

gridView1.Columns[1].Name

=

“Name“;

gridView1.Columns[2].Name

=

“Age“;

增加一个Group列进行分组

this.gridView1.GroupSummary.AddRange(new

DevExpress.XtraGrid.GridSummaryItem[]

{

new

DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count,“ID“,null,“(Count={0})“)});

增加一个Group列进行分组

this.gridView1.GroupSummary.AddRange(new

DevExpress.XtraGrid.GridSummaryItem[]

{

new

DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Max,“Age“,null,“(Max={0})“)});

设置并制作Foot下面的统计信息

this.gridView1.GroupFooterShowMode

=

DevExpress.XtraGrid.Views.Grid.GroupFooterShowMode.VisibleAlways;

this.gridView1.OptionsView.ShowFooter

=

true;

gridView1.Columns[2].SummaryItem.DisplayFormat

=

“(Age={0})“;

gridView1.Columns[2].SummaryItem.FieldName

=

“Age“;

gridView1.Columns[2].SummaryItem.SummaryType

=

DevExpress.Data.SummaryItemType.Sum;

}

设置成cardview格式

private

void

menuItem2_Click(object

sender,EventArgs

e)

{

gridControl1.MainView

=

this.cardView1;

}

设置成GridView格式

private

void

menuItem4_Click(object

sender,EventArgs

e)

{

gridControl1.MainView

=

this.gridView1

;

}

自己模仿着写吧,相信大家很快都会成为高手的。

    以上《GridControl控件学习总结》范文由一流范文网精心整理,如果您觉得有用,请收藏及关注我们,或向其它人分享我们。转载请注明出处 »一流范文网»最新范文»GridControl控件学习总结
‖大家正在看...
设为首页 - 加入收藏 - 关于范文吧 - 返回顶部 - 手机版
Copyright © 一流范文网 如对《GridControl控件学习总结》有疑问请及时反馈。All Rights Reserved