0

我有一个gridview,我将它的一些列分组..

这是我对它们进行分组的方式:

 void gvDetailsDefinition()
 {
            ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
            view.ColumnGroups.Add(new GridViewColumnGroup());
            view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
            view.ColumnGroups[0].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["ItemCode"]);
            view.ColumnGroups[0].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["ItemDescription"]);
            view.ColumnGroups[0].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["MeasurementUnitSelection"]);

            view.ColumnGroups.Add(new GridViewColumnGroup("January"));
            view.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());
            view.ColumnGroups[1].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["JanuaryQuantity"]);
            view.ColumnGroups[1].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["JanuaryVolume"]);

            view.ColumnGroups.Add(new GridViewColumnGroup("February"));
            view.ColumnGroups[2].Rows.Add(new GridViewColumnGroupRow());
            view.ColumnGroups[2].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["FebruaryQuantity"]);
            view.ColumnGroups[2].Rows[0].Columns.Add(gvSalesForecastDetails.Columns["FebruaryVolume"]);

            gvSalesForecastDetails.ViewDefinition = view;
}

我可以改变Font size and weightColumnGroup

这是它的结果:

在此处输入图像描述

4

1 回答 1

0

您必须使用 ViewCellFormatting 事件:

private void gvSalesForecastDetails_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement is GridHeaderCellElement)
        {
            if ((((string)(e.CellElement).Value) == "January" || ((string)(e.CellElement).Value) == "Feberuary" || ((string)(e.CellElement).Value) == "March"))
            {
                e.CellElement.Font = BOLD_FONT;//the font u want

                e.CellElement.ForeColor = Color.SteelBlue;
                e.CellElement.GradientStyle = GradientStyles.Solid;
                e.CellElement.DrawFill = true;
                e.CellElement.BackColor = Color.White;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            }
        }
    }
于 2016-06-15T15:42:44.520 回答