devexpress表格GridView默认属性配置

GridView默认属性配置

//GridView默认属性配置
public static void SetDefaultGridViewOption(GridView gvDetail)
{
		gvDetail.OptionsView.ColumnAutoWidth = false;  //自动列宽,关闭
		gvDetail.OptionsView.ShowGroupPanel = false; //分组,关闭
		gvDetail.OptionsMenu.EnableColumnMenu = true; //显示列菜单: 可以开启分组, 排序, 过滤, 删除列, 添加列等功能
		gvDetail.OptionsCustomization.AllowSort = true; //允许排序
		gvDetail.OptionsView.ShowFooter = true;  //显示表格尾
		gvDetail.OptionsNavigation.EnterMoveNextColumn = true;
		gvDetail.OptionsView.ShowAutoFilterRow = true;//显示自动过滤栏
		gvDetail.OptionsCustomization.AllowFilter = true;//显示列右上角的过滤按钮
		gvDetail.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Default; //过滤编辑栏自动隐藏
		gvDetail.OptionsBehavior.Editable = true;  //1,只有启用编辑才可以设置表格的只读
		gvDetail.OptionsBehavior.ReadOnly = false; //2,设置表格默认非只读,单元格才可以选中复制

		//3,设置所有单元格为只读, 需要编辑的单元格请单独去掉只读
		foreach (GridColumn c in gvDetail.Columns)
		{
				c.OptionsColumn.ReadOnly = true;  //单元格只读
				
				//数量列,默认格式化为整型显示
				if (c.Name.Contains("Qty"))
				{
						c.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
						c.SummaryItem.DisplayFormat = "{0:n0}";
				}
		}

		//表格尾默认显示记录数
		if (gvDetail.Columns.Count >= 2)
		{
				//记录数汇总
				gvDetail.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
				gvDetail.Columns[0].SummaryItem.DisplayFormat = "记录数:";
				gvDetail.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
				gvDetail.Columns[1].SummaryItem.DisplayFormat = "{0:n0}";

		}
}

获取已经勾选的行

//结束表格编辑,过滤出选中的数据,用于读取
public static DataTable GetSelectDataForRead(GridView gvMaster, DataView dvMaster, string RowFilter)
{
		if (null == gvMaster || null == dvMaster)
		{
				return null;
		}
		gvMaster.CloseEditor();
		gvMaster.UpdateCurrentRow();

		DataTable dtData = dvMaster.ToTable();
		dtData.DefaultView.RowFilter = RowFilter; // "Flag = 1";
		dtData = dtData.DefaultView.ToTable(); //只留下已经选中的单据
		return dtData;
}

相关推荐