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

dynamically added columns wont be filterable or groupable

3 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 17 Dec 2013, 04:58 PM
Hello
i am adding some comumns in my code behind to a radgridview
The problem i get is that these columns are not filterable neither groupable . I have some columns defnied in the xaml and these are filterable and groupable.

So i dont understand why the dinamicly created columns are not.

Here is my code

<telerik:RadGridView Name="GridViewListeConstituants" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Style="{DynamicResource RadGridViewStyle1}" HeaderRowStyle="{DynamicResource GridViewHeaderRowStyle1}"
                             Margin="5" ItemsSource="{Binding listeConstituants}" AutoGenerateColumns="False" >
            <telerik:RadGridView.RowStyleSelector>
                <telerik:ConditionalStyleSelector>
                    <telerik:StyleRule Condition="enCreation" Style="{DynamicResource RowEnCreationStyle}" >
                    </telerik:StyleRule>
                    <telerik:StyleRule Condition="enCreation=false" Style="{DynamicResource RowStandardStyle}">
                    </telerik:StyleRule>
                </telerik:ConditionalStyleSelector>
            </telerik:RadGridView.RowStyleSelector>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding LIBELLE}" Header="Libellé" HeaderCellStyle="{DynamicResource HeaderCellStyle1}">
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding UNITE}" Header="Unité" HeaderCellStyle="{DynamicResource HeaderCellStyle1}">
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding VALEURDEFAUT}" Header="Valeur par défaut" HeaderCellStyle="{DynamicResource HeaderCellStyle1}">
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Propriétés" HeaderCellStyle="{DynamicResource HeaderCellStyle1}" >
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Name="ButtonProprietes" Content="{Binding StringPropriete}" Click="ButtonProprietes_Click_1"></telerik:RadButton>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>


foreach (CONTEXTE monContexte in listeContextes)
            {
                Telerik.Windows.Controls.GridViewCheckBoxColumn maColonne = new Telerik.Windows.Controls.GridViewCheckBoxColumn();
                //Telerik.Windows.Controls.GridViewDataColumn maColonne = new Telerik.Windows.Controls.GridViewDataColumn();
                maColonne.HeaderCellStyle = this.FindResource("HeaderCellStyle1") as Style;
                maColonne.DataMemberBinding = new Binding("RowContextes[" + monContexte.LIBELLE + "]");
                maColonne.Name = "C"+ monContexte.ID_CONTEXTE.ToString();
                maColonne.Header = monContexte.LIBELLE;
                maColonne.Width =100;
                maColonne.TextAlignment = TextAlignment.Center;
                maColonne.CellStyle = this.FindResource("CheckBoxCellStyle") as Style;
                this.GridViewListeConstituants.Columns.Add(maColonne);
                maColonne.IsCustomSortingEnabled = true;
                maColonne.IsFilterable = true;
                maColonne.IsGroupable = true;
                maColonne.IsReorderable = true;
                maColonne.IsSortable = true;
                maColonne.IsThreeState = true;
                maColonne.DataType= System.Type.GetType("Boolean");
                //maColonne.
                 
            }


Any idea about what this isnt working?

3 Answers, 1 is accepted

Sort by
0
Alexandre
Top achievements
Rank 1
answered on 17 Dec 2013, 05:37 PM
After some test, it looks like the problem come from the fact i a am using a data row to bind the columns data.

if i try to add a column binded this way :

maColonne.DataMemberBinding = new Binding("RowContextes[mykey]");

it wont be groupable or sortable, but if it binded directly to a property:

maColonne.DataMemberBinding = new Binding("oneproperty");

it is groupable and filterable.

But i still need to create those columns from a collection or a dataRow or something containing multiples object. So how can i do this and keep the filterable and groupable thing?

0
Dimitrina
Telerik team
answered on 19 Dec 2013, 01:26 PM
Hello,

The columns will not be sort-able, filterable or group-able if the type of the bound data cannot be resolved. If your data is of type object, then you can try to explicitly set DataType for the bound column.

Does this help?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Alexandre
Top achievements
Rank 1
answered on 10 Feb 2014, 10:39 AM
Well i finally used a Dictionnary which is strongly typed and can also be call like dic["itemName"]  to do this.

that ways the component retrieve the data type and the columns are filterable and groupable
Tags
GridView
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Alexandre
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or