Datagrid : Sort Int Column From Xml

Sep 8, 2010 at 10:45 AM

Hi,

I have a XmlDataProvider, I bind any columns with the Datagrid like this :

	DataGridTextColumn tc = new DataGridTextColumn();
   tc.IsReadOnly = true;
        tc.Header = n1.SelectSingleNode(param).Attributes["libelle"].Value;
        tc.Binding = new System.Windows.Data.Binding() { XPath = param };
        paramDataGrid.Columns.Add(tc);

but when I want to sort numerics columns, the result is "1, 12, 145, 3, 45, 487" and not "1, 3, 12, 45,..."

 

I tried the DataGridTemplateColumn with this code :

				DataGridTemplateColumn tc = new DataGridTemplateColumn();
                                tc.IsReadOnly = true;
                                tc.CanUserSort = true;
                                tc.Header = n1.SelectSingleNode(param).Attributes["libelle"].Value;
                                tc.SortMemberPath = n1.SelectSingleNode(param).Name;

                                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));
                                Binding b = new System.Windows.Data.Binding() { XPath = @param };
                                b.Mode = BindingMode.TwoWay;
                                factory.SetBinding(TextBlock.TextProperty, b);

                                DataTemplate cellTemplate = new DataTemplate();
                                cellTemplate.DataType = System.Type.GetType("System.Int32");
                                cellTemplate.VisualTree = factory;
                                tc.CellTemplate = cellTemplate;
                                paramDataGrid.Columns.Add(tc);

I always tried with a Converter but the result is the same...

I need help to find the solution. Please.

 

 



 


Sep 17, 2010 at 8:04 AM

Anybody can help me ??