Hello,
I have a grid with columns grouping, being created dynamically:
public static GridColumn AddColumn(this RadGrid grid, string column, int width, string headerText = null, string sortExpr = null, string colGroupName = null)
{
if (string.IsNullOrEmpty(headerText))
headerText = column;
var boundColumn = new GridBoundColumn();
grid.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = column;
boundColumn.HeaderText = headerText;
boundColumn.UniqueName = column;
if (colGroupName != null)
{
boundColumn.ColumnGroupName = colGroupName;
boundColumn.AllowSorting = false;
}
else
{
if (string.IsNullOrEmpty(sortExpr))
sortExpr = column;
boundColumn.AllowSorting = false;
boundColumn.SortExpression = sortExpr;
}
return boundColumn;
}
public static GridColumnGroup AddColumnGroup(this RadGrid grid, string name, int width, string headerText, string parent = null)
{
var colGroup = new GridColumnGroup();
grid.MasterTableView.ColumnGroups.Add(colGroup);
colGroup.Name = name;
colGroup.HeaderText = headerText;
if (parent != null)
colGroup.ParentGroupName = parent;
return colGroup;
}
and in ascx.cs:
foreach (var indicator in ListIndicatori)
{
if (....)
{
List.AddColumn("Field_" + indicator.Id, 100, indicator.Denumire + "(" + indicator.UnitateMasura + ")");
DataTableSource.Columns.Add("Field_" + indicator.Id);
}
else
{
var groupName = "Group" + indicator.Id;
List.AddColumnGroup(groupName, 120, indicator.Denumire + "(" + indicator.UnitateMasura + ")");
List.AddColumn("Field_" + indicator.Id + "_LD", 40, "LD", colGroupName: groupName);
List.AddColumn("Field_" + indicator.Id + "_LQ", 40, "LQ", colGroupName: groupName);
List.AddColumn("Field_" + indicator.Id + "_VF", 40, "VF", colGroupName: groupName);
DataTableSource.Columns.Add("Field_" + indicator.Id + "_LD");
DataTableSource.Columns.Add("Field_" + indicator.Id + "_LQ");
DataTableSource.Columns.Add("Field_" + indicator.Id + "_VF");
}
}
where List is RadGrid declared in ascx file
I receive the error:
Invalid column group configuration! Column "Field_10_LQ" cannot be after column "Field_5"
The columns are not always the same (i.e Column "Field_53_LQ" cannot be after column "Field_7") and does not appears all the time, but I was not able to discover why and when (in which cases) it appears.
Any help will be appreciated!
Thanks,
Antonio
I have a grid with columns grouping, being created dynamically:
public static GridColumn AddColumn(this RadGrid grid, string column, int width, string headerText = null, string sortExpr = null, string colGroupName = null)
{
if (string.IsNullOrEmpty(headerText))
headerText = column;
var boundColumn = new GridBoundColumn();
grid.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = column;
boundColumn.HeaderText = headerText;
boundColumn.UniqueName = column;
if (colGroupName != null)
{
boundColumn.ColumnGroupName = colGroupName;
boundColumn.AllowSorting = false;
}
else
{
if (string.IsNullOrEmpty(sortExpr))
sortExpr = column;
boundColumn.AllowSorting = false;
boundColumn.SortExpression = sortExpr;
}
return boundColumn;
}
public static GridColumnGroup AddColumnGroup(this RadGrid grid, string name, int width, string headerText, string parent = null)
{
var colGroup = new GridColumnGroup();
grid.MasterTableView.ColumnGroups.Add(colGroup);
colGroup.Name = name;
colGroup.HeaderText = headerText;
if (parent != null)
colGroup.ParentGroupName = parent;
return colGroup;
}
and in ascx.cs:
foreach (var indicator in ListIndicatori)
{
if (....)
{
List.AddColumn("Field_" + indicator.Id, 100, indicator.Denumire + "(" + indicator.UnitateMasura + ")");
DataTableSource.Columns.Add("Field_" + indicator.Id);
}
else
{
var groupName = "Group" + indicator.Id;
List.AddColumnGroup(groupName, 120, indicator.Denumire + "(" + indicator.UnitateMasura + ")");
List.AddColumn("Field_" + indicator.Id + "_LD", 40, "LD", colGroupName: groupName);
List.AddColumn("Field_" + indicator.Id + "_LQ", 40, "LQ", colGroupName: groupName);
List.AddColumn("Field_" + indicator.Id + "_VF", 40, "VF", colGroupName: groupName);
DataTableSource.Columns.Add("Field_" + indicator.Id + "_LD");
DataTableSource.Columns.Add("Field_" + indicator.Id + "_LQ");
DataTableSource.Columns.Add("Field_" + indicator.Id + "_VF");
}
}
where List is RadGrid declared in ascx file
I receive the error:
Invalid column group configuration! Column "Field_10_LQ" cannot be after column "Field_5"
The columns are not always the same (i.e Column "Field_53_LQ" cannot be after column "Field_7") and does not appears all the time, but I was not able to discover why and when (in which cases) it appears.
Any help will be appreciated!
Thanks,
Antonio