1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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();
        }
    }
}