#region
|
|
using CSFrameworkV5.Business;
|
using CSFrameworkV5.Common;
|
using DevExpress.XtraGrid.Columns;
|
using DevExpress.XtraGrid.Views.Grid;
|
|
#endregion
|
|
namespace CSFrameworkV5.Library.CommonClass
|
{
|
/// <summary>
|
/// 自动设置表格栏位标题
|
/// </summary>
|
public class ColumnFieldTool
|
{
|
/// <summary>
|
/// 自动设置表格栏位标题
|
/// </summary>
|
/// <param name="view">表格</param>
|
/// <param name="bindingTableName">物理表名,从数据库取该表的字段标题</param>
|
public static void SetColumnFieldTitle(GridView view,
|
string bindingTableName)
|
{
|
if (view.GridControl.DataSource == null) return;
|
|
//获取表的字段显示名称
|
var fieldNames =
|
CommonData.GetTableFieldsDef(bindingTableName, true);
|
|
view.BeginInit();
|
foreach (GridColumn column in view.Columns)
|
{
|
var rows =
|
fieldNames.Select("FieldName='" + column.FieldName + "'");
|
if (rows.Length > 0)
|
column.Caption = ConvertEx.ToString(rows[0]["DisplayName"]);
|
else
|
column.VisibleIndex = -1;
|
}
|
|
view.EndInit();
|
}
|
}
|
}
|