Winson.Thoughts.ToString()

Happy Programming, Happy Life

  博客园 :: 首页 :: 博问 :: 闪存 :: :: :: :: 管理 ::

场景:类Employee是包含子类Department, 想在UltraWinGrid中显示DepartmentName而不是DepartmentID。 

方法1 :Override Department的ToString()方法,然后用直接BindColumn即可。 

方法2 :新建一个UnBoundColumn,属性KEY为"DepartmentName", 然后在UltraWinGrid的InitializeRow方法中写代码如下:

        private void gridEmployeeList_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
        
{
            Department d 
= new Department();
            
string desc = d.GetById(e.Row.Cells["DepartmentID"].Value.ToString(), false).DeartmentName;
            e.Row.Cells[
"DeartmentName"].Value = desc;
        }

另外一个TIP: WinForm的标准控件GridView中的AutoGenerateColumn属性,在UltraWinGrid中的对应方法为: 

     IList list = Employee.GetList(); 
     
this.gridEmployeeList.SetDataBinding(list, nulltruefalse);
     
this.gridEmployeeList.DataBind();

其中list返回的是所有属性的集合,然后在UltraWinGrid的设计器中的Data Schema的选择手动添加,然后将要显示的列添加到BoundColumn中。

posted on 2008-07-26 14:49  winsonweb  阅读(382)  评论(0编辑  收藏  举报