This is a migrated thread and some comments may be shown as answers.

Dynamic datagrid columns creation problems

2 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 24 Jan 2012, 03:21 PM

Hi,

In my project, I have to create GridViewDataColumn for my RadGridView dynamically. When I finish creating my columns, I load data into my grid but the sort, filter and the grouping doesn't work :( I cannot see my filter button and if I try to drag a column header into the group panel, nothing happen.

Here is in my grid:

<telerik:RadGridView x:Name="radGridViewList" Margin="5 0 5 5" Visibility="Visible" RowDetailsVisibilityMode="Collapsed" FrozenColumnCount="1"

RowIndicatorVisibility="Collapsed" IsReadOnly="True" AutoGenerateColumns="False" CanUserFreezeColumns="False" Grid.Row="3"

CanUserResizeColumns="True" ShowColumnFooters="True" ShowGroupFooters="True" SelectionMode="Extended" IsSynchronizedWithCurrentItem="True" />

 

here is the code-behind:

static public void SetColumns(RadGridView pGrid, ColumnDescriptor[] pColumnNames)

{

if (pColumnNames != null)

{

SortedList<int, GroupDescriptor> grouping = new SortedList<int, GroupDescriptor>();

for (int iColumnIndex = 0; iColumnIndex < pColumnNames.Length; iColumnIndex++)

{

ColumnDescriptor oneName = pColumnNames[iColumnIndex];

Telerik.Windows.Controls.GridViewDataColumn oneColumn = new Telerik.Windows.Controls.GridViewDataColumn();

oneColumn.Header = oneName.ColumnName;

//Apply proper column display format.

switch (oneName.Format.ToUpper())

{

case "$":

oneColumn.DataFormatString = "C2";

break;

case "D":

oneColumn.DataFormatString = "yyyy'-'MM'-'dd";

break;

case "H":

oneColumn.DataFormatString = "HH':'mm";

break;

case "DH":

oneColumn.DataFormatString = "yyyy'-'MM'-'dd' 'HH':'mm";

break;

}

oneColumn.Width = new GridViewLength(1, GridViewLengthUnitType.Star);

oneColumn.ShowFilterButton = true;

oneColumn.IsSortable = true;

oneColumn.IsFilterable = true;

oneColumn.IsGroupable = true;

oneColumn.DataMemberBinding = new Binding(string.Format("ElementCells[{0:D}]", iColumnIndex));

oneColumn.TextAlignment = (TextAlignment)oneName.TextAlignment;

oneColumn.HeaderTextAlignment = (TextAlignment)oneName.TextAlignment;

//Create proper aggregate functions.

if (oneName.Agregation != AgregationFunction.None)

{

AddAggregateToColumns(ref oneColumn, oneName, string.Format("ElementCells[{0:D}]", iColumnIndex));

}

//Grouping field.

if (oneName.GroupingPosition != 0)

{

grouping.Add(Math.Abs(oneName.GroupingPosition),

new GroupDescriptor { DisplayContent = oneName.ColumnName, Member = string.Format("ElementCells[{0:D}]", iColumnIndex),

SortDirection = oneName.GroupingPosition > 0 ? ListSortDirection.Ascending : ListSortDirection.Descending});

}

//Add the column to the grid.

pGrid.Columns.Add(oneColumn);

}

//If grouping exist, add it to the grid.

if (grouping.Count != 0)

{

foreach (KeyValuePair<int, GroupDescriptor> oneGrouping in grouping)

{

pGrid.GroupDescriptors.Add(oneGrouping.Value);

}

}

}

}

Thank's

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Jan 2012, 02:05 PM
Hello,

 I have tested a scenario similar to yours and I found out that you need to set a DataType for the GridViewDataColumn and then all the sort, filter and the grouping will be working fine.

Please let me know if this fixed the problem. 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oliver
Top achievements
Rank 1
answered on 25 Jan 2012, 04:34 PM
Hi,

you got it :) The problem was fixed!!!

BTW, for active user like me you don't have a "special free renewal service subscription" :0

Thank's

Tags
GridView
Asked by
Oliver
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or