使用UltraWinGrid显示具有一些自定义网格外观设置的分层数据?

时间:2013-07-08 06:14:11

标签: c# winforms infragistics ultrawingrid

我的对象看起来像这样:

public class ComponentProperty
{        
    public string Property { get; set; }
    public object Value { get; set; }
    public string DataType { get; set; }
    public string PropertyKey { get; set; }
    public string Unit { get; set; }
    public string DependencyType { get; set; }
    public object ListType { get; set; }

    public List<ComponentProperty> Properties { get; set; }
}

我在BindingList的以下形式中构建了信息,其中Output是:

public class ComponentPropertyList: BindingList<ComponentProperty>
{

}

情境:

组件属性列表绑定到 Infragistics Ultra WinGrid 以生成Master-Detail View,我在网格设置中进行了以下自定义:

void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
    ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Synchronized;
    e.Layout.Bands[0].Override.HeaderAppearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
    ultraGrid1.DisplayLayout.Appearance.BackColor = Color.White;
    ultraGrid1.DisplayLayout.Appearance.BackColor2 = Color.White;
    ultraGrid1.DisplayLayout.Override.ActiveRowAppearance = null;
    ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.None;
    ultraGrid1.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.None;
    ultraGrid1.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.None;
    ultraGrid1.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.Default;
    ultraGrid1.DisplayLayout.Bands[0].ColHeadersVisible = true;
    ultraGrid1.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
    ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.NoEdit;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellActivation = Activation.AllowEdit;
    //Infosys: Nikita - Added for #1143 - START
    ultraGrid1.DisplayLayout.Bands[0].Columns["Unit"].CellActivation = Activation.NoEdit;
    //Infosys: Nikita - Added for #1143 - END
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BorderColor = Color.Black;
    ultraGrid1.DisplayLayout.Override.RowAppearance.TextVAlign = VAlign.Middle;
    // e.Layout.Bands[0].Columns[1].Width = 90;
    ultraGrid1.DisplayLayout.Scrollbars = Scrollbars.Automatic;
    ultraGrid1.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
    ultraGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
    ultraGrid1.DisplayLayout.Bands[0].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
    ultraGrid1.DisplayLayout.Bands[0].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
    ultraGrid1.DisplayLayout.Bands[0].Columns[2].Hidden = true;
    ultraGrid1.DisplayLayout.Bands[0].Columns[3].Hidden = true;
    //ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.Collevel].Hidden = true;
    //ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.ColID].Hidden = true;
    //ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.Colparentid].Hidden = true;
    ultraGrid1.DisplayLayout.Bands[0].Columns["DependencyType"].Hidden = true;
    ultraGrid1.DisplayLayout.Bands[0].Columns["ListType"].Hidden = true;
    //ultraGrid1.DisplayLayout.Bands[0].Override.AllowColSizing = AllowColSizing.Synchronized;
    ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.Default;


    //ultraGrid1.DisplayLayout.Bands[0].Columns[1].TabStop = false;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackColor = Color.White;

    ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
    ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;

    ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].CellAppearance.BackColor = Color.White;

    ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.CellsOnly;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].SupportDataErrorInfo = DefaultableBoolean.True;

    ultraGrid1.DisplayLayout.Bands[0].Columns[0].Width = 200;
    ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].Width = 120;
    ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].TabIndex = 0;
    ultraGrid1.DisplayLayout.Bands[0].Columns["Unit"].Width = 60;

    for (int rowCount = 0; rowCount < ultraGrid1.Rows.Count; rowCount++)
    {
        UltraGridRow row = ultraGrid1.Rows[rowCount];
        if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value)))
        {
            row.Cells[1].Appearance.BackColor = Color.White;
        }
    }

    ultraGrid1.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
    ultraGrid1.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Solid;


    ultraGrid1.DisplayLayout.Override.GroupByRowSpacingAfter = 0;
    ultraGrid1.DisplayLayout.Override.GroupByRowSpacingBefore = 0;
    ultraGrid1.DisplayLayout.Override.HeaderPlacement = HeaderPlacement.OncePerGroupedRowIsland;

    if (ultraGrid1.DisplayLayout.Bands.Count > 1)
    {
        ultraGrid1.DisplayLayout.Bands[1].ColHeadersVisible = false;
        ultraGrid1.DisplayLayout.Bands[1].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
        ultraGrid1.DisplayLayout.Bands[1].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
        ultraGrid1.DisplayLayout.Bands[1].Columns[0].CellActivation = Activation.NoEdit;
        ultraGrid1.DisplayLayout.Bands[1].Columns[4].CellActivation = Activation.NoEdit;
        ultraGrid1.DisplayLayout.Bands[1].Columns[2].Hidden = true;
        ultraGrid1.DisplayLayout.Bands[1].Columns[3].Hidden = true;
        ultraGrid1.DisplayLayout.Bands[1].Columns["DependencyType"].Hidden = true;
        ultraGrid1.DisplayLayout.Bands[1].Columns["ListType"].Hidden = true;
        ultraGrid1.DisplayLayout.Bands[1].Columns[0].Width = 120;
        //ultraGrid1.DisplayLayout.Bands[1].Columns[0].TabStop = false;
        ultraGrid1.DisplayLayout.Bands[1].Columns["Value"].Width = 180;
        ultraGrid1.DisplayLayout.Bands[1].Columns["Value"].TabIndex = 0;
        ultraGrid1.DisplayLayout.Bands[1].Columns["Unit"].Width = 60;
        //ultraGrid1.DisplayLayout.Bands[1].Columns[Constants.ColUnit].TabStop = false;
        ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
        if (e.Layout.Bands[1].Columns.Exists(" ") == true)
        {
            ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Width = 0;
        }
        if (e.Layout.Bands[1].Columns.Exists(" ") == false)
        {
            ultraGrid1.DisplayLayout.Bands[1].Columns.Add(" ");
            ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Header.VisiblePosition = 0;
            ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Width = 0;
        }
        if (ultraGrid1.DisplayLayout.Bands.Count > 2)
        {

            ultraGrid1.DisplayLayout.Bands[2].ColHeadersVisible = false;
            ultraGrid1.DisplayLayout.Bands[2].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
            ultraGrid1.DisplayLayout.Bands[2].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
            ultraGrid1.DisplayLayout.Bands[2].Columns[0].CellActivation = Activation.NoEdit;
            ultraGrid1.DisplayLayout.Bands[2].Columns[4].CellActivation = Activation.NoEdit;
            //ultraGrid1.DisplayLayout.Bands[2].Override.AllowColSizing = AllowColSizing.None;
            ultraGrid1.DisplayLayout.Bands[2].Columns[2].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[2].Columns[3].Hidden = true;

            ultraGrid1.DisplayLayout.Bands[2].Columns["DependencyType"].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[2].Columns["ListType"].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[2].Columns[0].Width = 200;
            ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].Width = 120;
            ultraGrid1.DisplayLayout.Bands[2].Columns["Unit"].Width = 60;
            ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
            //ultraGrid1.DisplayLayout.Bands[2].Columns[0].TabStop = false;
            ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].TabIndex = 0;
            //ultraGrid1.DisplayLayout.Bands[2].Columns[Constants.ColUnit].TabStop = false;
            ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
            ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.
            if (e.Layout.Bands[2].Columns.Exists(" ") == true)
            {
                ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Width = 0;
            }
            if (e.Layout.Bands[2].Columns.Exists(" ") == false)
            {
                ultraGrid1.DisplayLayout.Bands[2].Columns.Add(" ");
                ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Header.VisiblePosition = 0;
                ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Width = 0;
            }
        }
    }
    e.Layout.Bands[0].Override.CellAppearance.BorderAlpha = Alpha.Transparent;
    e.Layout.Bands[0].Override.SelectedCellAppearance.ForeColor = Color.Black;
    e.Layout.Bands[0].Override.RowAppearance.BorderAlpha = Alpha.Transparent;
    e.Layout.Bands[0].Override.CellAppearance.BackColorAlpha = Alpha.Transparent;
    e.Layout.Bands[0].Columns[0].CellActivation = Activation.NoEdit;
    e.Layout.Bands[0].Columns[1].CellActivation = Activation.NoEdit;
    e.Layout.Bands[0].Columns[2].CellActivation = Activation.NoEdit;
    ultraGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
    ultraGrid1.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
    ultraGrid1.DisplayLayout.Appearance.BackColor = Color.White;
    //ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.None;
    //ultraGrid1.DisplayLayout.Override.AllowRowLayoutColMoving = GridBagLayoutAllowMoving.None;
    ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;
    ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextCell;


    if (e.Layout.Bands[0].Columns.Exists(" ") == true)
    {
        ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Width = 0;
        //ultraGrid1.DisplayLayout.Bands[0].Columns[" "].ColSpan = 3;
    }
    if (e.Layout.Bands[0].Columns.Exists(" ") == false)
    {
        ultraGrid1.DisplayLayout.Bands[0].Columns.Add(" ").DataType = typeof(bool);
        ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Header.VisiblePosition = 0;
        ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Width = 0;
        // ultraGrid1.DisplayLayout.Bands[0].Columns[" "].ColSpan = 3;
        ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
        UltraGridColumn checkBox = ultraGrid1.DisplayLayout.Bands[0].Columns[" "];
    }

    foreach (UltraGridBand band in ultraGrid1.DisplayLayout.Bands)
    {
        band.HeaderVisible = false;
    }
}

componentProperties集合可能具有N Level,具体取决于值。

CompoentProperty 1
--------&GT; SubProperty1
----------------&GT; SubSubProperty1
----------------&GT; SubSubProperty1
CompoentProperty 2
--------&GT; SubProperty2
----------------&GT; SubSubProperty2
----------------&GT; SubSubProperty2
----------------------&GT; SubSubProperty3
----------------------&GT; SubSubProperty3
---------------------------&gt; SubSubProperty NN

问题:

布局不正确,将DataSource分配给网格后有很多条带ComponentProperties类和指定的Column Size对它没有任何影响。 以前,我使用datatable作为需要替换对象数据源的数据源。是否需要使用对象数据源进行任何设置。

Lost of band showing rather than just 3 bands if i have 3 level hierarchy

1 个答案:

答案 0 :(得分:3)

我从Infragistics fourm得到了一些解决方案,解决了布局问题。在我使用IList时进行检查时,在表单加载事件中设置MaxBandDepth Property后,这些设置工作正常。

// Load only upto two descendant bands. So even if the data source has more than 3 level 
// deep hierarchy, the UltraGrid will only make use of first two levels and ignore the 
// levels deeper than that.
    this.ultraGrid1.DisplayLayout.MaxBandDepth = 3;

发生的问题类似于以下主题中提出的问题:
First Column of Wingrid Extending too large when datasource is IList

  

默认情况下,网格会同步每个波段的列宽。所以   在这种情况下 你有一个递归数据源,那里   基本上是无限数量的波段,每个波段都是网格   缩进一点点。这意味着第一列变得非常大   为了容纳压痕一路向下   层次结构。 默认情况下,网格限制为100个深度带,   但这仍然意味着100级的缩进。

     

因此,有很多方法可以解决这个问题。

     

将网格上的MaxBandDepth设置为较小的值。我推荐一个值   在5到8之间。这将给你相当不错的表现   体面的机器和大多数用户可能不会钻取超过5   无论如何,水平。您可以将AllowColSizing设置为Free。这将停止   网格来自同步列宽并允许每个波段   列要独立调整大小。

参考文献:
MaxBandDepth Changing After Datasource Set
MaxBandDepth is not being used when the datasource is set
Ultragrid Hierarchical DataSource with Multiple Level Paths
UltraGrid hierarchy