Custom sort xml bound DataGridView

I have a DataGridView bound to xml file. I would like to sort by first column and treat values as integers (not strings).

XmlDataDocument xml = new XmlDataDocument(); xml.DataSet.ReadXml("file.xml"); dataGridView.DataSource = new BindingSource(xml.DataSet, "Item");

  • Sort(IComparer) doesn't work
  • Sort(DataGridViewColumn,ListSortDirection) treats all values as strings
  • SortCompare event isn't triggered

What do I have to do to make this work? Inherit DataGridView and override Sort? Sort BindingSource? Sort DataSet?

Note to future readers:

Accepted answer doesn't work for my code snippet. DataType must be changed before data is loaded. DataSet should be manually created:

DataTable table = new DataTable("Item"); table.Columns.Add(new DataColumn("id", typeof(int))); table.Columns.Add(new DataColumn("name", typeof(string))); DataSet set = new DataSet(); set.Tables.Add(table); set.ReadXml("file.xml", XmlReadMode.IgnoreSchema); dataGridView.DataSource = new BindingSource(set, "Item");

-------------Problems Reply------------

You need to change the DataSet so that the column's DataType is System.Int32.

Category:c# Views:0 Time:2009-12-20

Related post

  • Custom Sorting on a DataGridView 2009-09-04

    I found a few questions similar to this one here on SO, but none that matched this problem, so here we go. I've got a DataGridView showing members of a team. All the team members have an assigned role within the team listed in one of the columns. Exa

  • DataGridView Custom Sort in WinForm 2010-08-18

    My DataGridView control currently sorts using the Sort property of the bound data, but it isn't doing what I want it to do. I have a column called Employee that is displayed as "Firstname Lastname". When I sort by Employee, Amy Z_Lastname is listed b

  • DataGridView Custom Sorting 2011-08-18

    I have a DataGridView with 6 columns. Example: column1 column2 column3 column4 column5 column6 J6 RES-0112G 123.123 456.456 180 1111 FID2 FIDUCIAL 5.123 -50.005 90 FIDUCIAL R100 RES-0113G 1.1 -123.123 90 1111 C12 CAP-1234H -99.99 -987.123 45 2222 Q1

  • Datagridview in C# - custom sorting of column 2012-03-28

    I have a databound (Datatable) datagridview in C#. The datatable is filled with the Load(IDataReader) method. The user is able to sort the columns of the DGV by clicking the header. Now I have one column (which originally in the database is a text-co

  • How can I use custom sorting on an NSTableView bound to an NSArrayController? 2010-09-27

    I have an NSTableView connected to an NSArrayController by setting the column values in interface builder to the appropriate keys in the NSArrayController. I'd like to use a custom sorting order, specifically, compare:options: with NSNumericSearch. W

  • What causes a WPF ListCollectionView that uses custom sorting to re-sort its items? 2009-03-02

    Consider this code (type names genericised for the purposes of example): // Bound to ListBox.ItemsSource _items = new ObservableCollection<Item>(); // ...Items are added here ... // Specify custom IComparer for this collection view _itemsView =

  • How to sort xml data using classic asp(vbscript) with out xpath? 2009-06-16

    <rooms> <room> <roomname>Single</roomname> <roomid>1</roomid> <Price>100</Price> <Adult>1</Adult> <child>0</child> </room> </rooms> <rooms> <room> <roo

  • Is it possible to do a custom sort on a GridView 2010-01-13

    I need to sort a GridView (Not DataGridView, it's not the same thing) that is in need of a complex sort and I don't know how it can be done. I have two column, one containing a date and another containing a priority. If the date is lesser or equal to

  • Custom sorting logic for groups using CollectionViewSource 2010-05-11

    I have a list of "stuff" which needs to be filtered then displayed in a grouped and sorted manner. The data needed to calculate the grouping and sorting order is not available as simple properties - there needs to be some work done in code to calcula

  • Custom Sort of Magento Collection? 2011-04-19

    Here's the thing, I have product collection that I need to sort by their size. The size attribute values are XS, S, M, L, XL. When I put simply addAttributeToSort('size', 'DESC') it sorts them by alphabetical order of size attribute values (XS, XL, S

  • custom sorting of Hashtable in C# (not by keys) 2011-06-24

    I need to sort the data in a Hashtable by a property of the object added to the collection. how to do that? my project uses .NET 2.0, so I can't use any features that do not work by default in .NET 2.0 runtime (I may be able to use some of the C# 3.0

  • How do I use CollectionViewSource to sort xml records by date? 2011-11-07

    I have the following XML: <Memories> <Memory Title="blah blah" ID="1"> <ImageFile>Data/Images/01.jpg</ImageFile> <Blurb>We did blah</Blurb> <Date>06/11/2009</Date> </Memory> <Memory Title="Grad

  • PHP: How to sort XML alphabetically by attribute before "for each" loop 2012-03-01

    The setup: I have an external XML file I have no control over, here is it: 001.xml <?xml version="1.0" encoding="utf-8"?> <Gallery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="001" Na

  • Add Custom TextboxCell to a DataGridView control that contains a button to open the FileDialog 2008-09-15

    I would like to add a DataGridViewTextBoxCell cell to a DataGridViewCell control, but as well as being able to type in the text cell as normal it must also contain a '...' button that once clicks brings up the OpenFileDialog window to allow the user

  • jQuery javascript custom sort procedure works in Firefox, but IE doesn't seem to get it- (copy-paste example code) 2009-06-04

    i've built this sample code based on a real problem I have in an application. I've got a custom sort procedure to sort jQuery arrays. A container contains a list of items with special attributes. For sorting: Loads all items in temp array Clears the

  • Custom sorting on UltraWebGrid - ASP .NET 2009-06-10

    How can I accomplish custom sorting on the Infragistics UltraWebGrid? I've tried to hadle the SortColumn event and it works, however, whenever I click the column header, the columns are sorted via JavaScript in the website before the event is fired i

  • How to use DataGridViewButtonColumn in non bound DataGridView 2009-06-23

    Using WinForms, C# .Net 2.0 I'm adding rows to a non bound DataGridView. I would like to have a DataGridViewButtonColumn in one of the columns that deletes that row when clicked. When I try to add a Click event to the DataGridViewButtonColumn, there

  • Customizing Sort Order of C# Arrays 2009-06-24

    This has been bugging me for some time now. I've tried several approaches and none have worked properly. I'm writing and IRC client and am trying to sort out the list of usernames (which needs to be sorted by a users' access level in the current chan

  • custom sorting or ordering a table without resorting the whole shebang 2009-07-29

    For ten years we've been using the same custom sorting on our tables, I'm wondering if there is another solution which involves fewer updates, especially since today we'd like to have a replication/publication date and wouldn't like to have our repli

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.212 (s). 11 q(s)