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

Sort not working when i bind a dictionary to the gridview

1 Answer 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ramya
Top achievements
Rank 1
Ramya asked on 03 Oct 2011, 02:11 PM
Hi Support,
               
                     i am binding a dictionary to radgridview at runtime  using a converter sort shoul happen when i click on header columns.I attached sortdescriptor and column
descriptor but its not working any help highly appreciable and even i attached a event still result is same
CodeBehind(xaml.cs)
==========

 

 

public UserControl1()

 

{

InitializeComponent();

 

 

Dictionary<string, string> dict = new Dictionary<string, string>();

 

dict.Add(

 

"Name", "Muneer");

 

dict.Add(

 

"Age", "23");

 

dict.Add(

 

"Address", "Ameerpet");

 

 

 

Dictionary<string, string> dict1 = new Dictionary<string, string>();

 

dict1.Add(

 

"Name", "Nag Srinivas");

 

dict1.Add(

 

"Age", "24");

 

dict1.Add(

 

"Address", "Yousufguda");

 

lstDict1.Add(dict);

lstDict1.Add(dict1);

 

 

foreach (var dictionary in lstDict1)

 

{

 

 

foreach (KeyValuePair<string, string> pair in dictionary)

 

{

 

 

GridViewDataColumn dataCol = null;

 

dataCol = (

 

GridViewDataColumn)TableTypeChart.Columns[pair.Key];

 

 

 

if (dataCol == null)

 

{

dataCol =

 

new GridViewDataColumn();

 

dataCol.Header = pair.Key;

dataCol.UniqueName = pair.Key;

dataCol.SortMemberPath = pair.Key;

dataCol.Width =

 

new GridViewLength(75, GridViewLengthUnitType.Auto);

 

dataCol.DataMemberBinding =

 

new Binding()

 

{

Converter =

 

new DictionaryConverter(pair.Key)

 

};

 

TableTypeChart.Columns.Add(dataCol);

 

}

}

}

 

TableTypeChart.ItemsSource = lstDict1;

}

 Xaml Page
=========

 

 

 

<telerikGrid:RadGridView x:Name="TableTypeChart" d:LayoutOverrides="Width" ShowGroupPanel="False"

 

 

 

Background="{x:Null}" AlternateRowBackground="#FF1D1D1D" BorderBrush="Black"

 

 

 

Foreground="#FF000000" VerticalGridLinesBrush="Black" HorizontalGridLinesBrush="Black"

 

 

 

ColumnReordered="StandardGridView_ColumnReordered" Sorting="TableTypeChart_Sorting"

 

 

 

AutoGenerateColumns="False" IsFilteringAllowed="True" GroupPanelBackground="{x:Null}"

 

 

 

CanUserSortColumns="True" GroupPanelForeground="{x:Null}" CanUserFreezeColumns="False" CanUserReorderColumns="True" CanUserResizeColumns="True"

 

 

 

CanUserDeleteRows="False" CanUserInsertRows="False" CanUserSelect="True" RowIndicatorVisibility="Collapsed" d:IsHidden="True" />

 





Thanks and regards,
Munna

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Oct 2011, 09:04 AM
Hello,

 It will be better to use dynamic objects instead similar to my blog post:
http://blogs.telerik.com/vladimirenchev/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx

All the best,
Vlad
the Telerik team

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

Tags
GridView
Asked by
Ramya
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or