可以在设置KeyFieldName前,将OptionsBehavior.PopulateServiceColumns属性设置为true,就会显示KeyFieldName,ParentFieldName字段
trlBM.DataSource = dtShow; trlBM.OptionsBehavior.PopulateServiceColumns = true; trlBM.KeyFieldName = "DEPTID"; trlBM.ParentFieldName = "PARENTID";
也可以在设置了KeyFieldName,ParentFieldName了之后,手动添加列,指定只显示KeyFieldName列
trlBM.DataSource = dtShow; trlBM.KeyFieldName = "DEPTID"; trlBM.ParentFieldName = "PARENTID"; trlBM.Columns.AddField("DEPTID");