DataGrid, sort numeric column after parsing xml

I parsed a xml file to a DataGrid.
Now i'd like to sort a column with numeric values.

I figured out that everything is sorted as a string value.
How can i sort this column as a numeric value.
Found some examples with Google, but nothing works for me.

Anthony. 


0
Anthony
4/10/2010 12:51:55 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

11 Replies
873 Views

Similar Articles

[PageSpeed] 3

Anthony wrote:
> I parsed a xml file to a DataGrid.
> Now i'd like to sort a column with numeric values.
> 
> I figured out that everything is sorted as a string value.
> How can i sort this column as a numeric value.

Are you using a DataSet and ReadXml()?
The right approach is to define an XML schema that defines the right 
numeric type you want, then use ReadXmlSchema() on the DataSet before 
you load the XML instance document with the ReadXml() method.

-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/
0
Martin
4/10/2010 12:55:15 PM
Hi,

This is likely because they are still strings. Not sure how you parse the 
file but it would be best to expose each column under its expected type 
(dates, integers, booleans or whatever). Here it seems to me that you just 
expose all values as strings...

How do you bind this XML file to your datagrid ?

--
Patrice



"Anthony" <Anthony@anti.spam.com> a �crit dans le message de 
news:eMSRayK2KHA.4580@TK2MSFTNGP05.phx.gbl...
>I parsed a xml file to a DataGrid.
> Now i'd like to sort a column with numeric values.
>
> I figured out that everything is sorted as a string value.
> How can i sort this column as a numeric value.
> Found some examples with Google, but nothing works for me.
>
> Anthony.
> 

0
Patrice
4/10/2010 12:59:26 PM
> This is likely because they are still strings. Not sure how you parse the 
> file but it would be best to expose each column under its expected type 
> (dates, integers, booleans or whatever). Here it seems to me that you just 
> expose all values as strings...

You should have a "XML To Schema" item in VS that will infer a schema from 
your XML file. Then you'll be able to tweak the schema if needed and to use 
this schema when loading the XML file so that its data are exposed with the 
type they should have...

--
Patrice

0
Patrice
4/10/2010 1:11:12 PM
            XmlDataDocument xmlDatadoc = new XmlDataDocument();
            xmlDatadoc.DataSet.ReadXml(@"d:\myxmlfile.xml");
            DataSet ds = new DataSet("books");
            ds = xmlDatadoc.DataSet;
            dataGridView1.DataSource = ds.DefaultViewManager;
            dataGridView1.DataMember = "title";

Anthony



0
Anthony
4/10/2010 1:12:12 PM
Anthony wrote:
>             XmlDataDocument xmlDatadoc = new XmlDataDocument();
>             xmlDatadoc.DataSet.ReadXml(@"d:\myxmlfile.xml");
>             DataSet ds = new DataSet("books");
>             ds = xmlDatadoc.DataSet;
>             dataGridView1.DataSource = ds.DefaultViewManager;
>             dataGridView1.DataMember = "title";

You don't need the XmlDataDocument but you need an XML schema for your 
XML document. Visual Studio can generate one for you, of course you 
might need to edit schema types to what you want. Then use e.g.
   DataSet ds = new DataSet();
   ds.ReadXmlSchema("schema.xsd");
   ds.ReadXml("file.xml");


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/
0
Martin
4/10/2010 1:18:55 PM
> You don't need the XmlDataDocument but you need an XML schema for your XML 
> document. Visual Studio can generate one for you, of course you might need 
> to edit schema types to what you want. Then use e.g.
>   DataSet ds = new DataSet();
>   ds.ReadXmlSchema("schema.xsd");
>   ds.ReadXml("file.xml");

Works exelent !
What's the best place to save the schema?
If possible i'd like to integrate it with my project.
(i need to parse a xml file from another application. So normally there's no 
schema available)

Anthony


0
Anthony
4/10/2010 1:43:18 PM
> You don't need the XmlDataDocument but you need an XML schema for your XML 
> document. Visual Studio can generate one for you, of course you might need 
> to edit schema types to what you want. Then use e.g.
>   DataSet ds = new DataSet();
>   ds.ReadXmlSchema("schema.xsd");
>   ds.ReadXml("file.xml");

Is it possible to use Linq in the 'same' way ?
(I need a query for some elements)

Anthony 


0
Anthony
4/10/2010 4:48:41 PM
Anthony wrote:
>> You don't need the XmlDataDocument but you need an XML schema for your XML 
>> document. Visual Studio can generate one for you, of course you might need 
>> to edit schema types to what you want. Then use e.g.
>>   DataSet ds = new DataSet();
>>   ds.ReadXmlSchema("schema.xsd");
>>   ds.ReadXml("file.xml");
> 
> Is it possible to use Linq in the 'same' way ?
> (I need a query for some elements)

What kind of LINQ do you want to do? There is LINQ to DataSet that 
allows you querying your DataSet. There is LINQ to XML that allows 
querying an XML document but for that you need to load the XML document 
into a System.Xml.Linq.XDocument (or XElement) and there is no 
connection between a DataSet and an XDocument.


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/
0
Martin
4/10/2010 5:24:43 PM
> What kind of LINQ do you want to do? There is LINQ to DataSet that allows 
> you querying your DataSet. There is LINQ to XML that allows querying an 
> XML document but for that you need to load the XML document into a 
> System.Xml.Linq.XDocument (or XElement) and there is no connection between 
> a DataSet and an XDocument.

Don't know what's the best solution. (no experience so far)
I need to make a query (xml file or DataSet) and add the final results to my 
DataGrid.
Maybe you can give me some advice ?

Did you read my previous quetion about the schema ?

Anthony



0
Anthony
4/10/2010 5:49:52 PM
Anthony wrote:

> What's the best place to save the schema?
> If possible i'd like to integrate it with my project.
> (i need to parse a xml file from another application. So normally there's no 
> schema available)

If you want to integrate the schema with your application then you could 
embed it as a resource in your assembly. You would then need to load it with
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcestream.aspx 
and pass that stream to the ReadXmlSchema method.


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/
0
Martin
4/10/2010 6:00:15 PM
> What kind of LINQ do you want to do? There is LINQ to DataSet that allows 
> you querying your DataSet. There is LINQ to XML that allows querying an 
> XML document but for that you need to load the XML document into a 
> System.Xml.Linq.XDocument (or XElement) and there is no connection between 
> a DataSet and an XDocument.

More specifically:
Is there a way to populate a DataSet via a LINQ query?



0
Anthony
4/11/2010 11:24:14 AM
Reply:

Similar Artilces:

Adding a leading space to a numeric column
Group: How can I add a leading space to a column of numbers in excel? Excel 2007 For example: 12345 54321 98761 I need a space peceding the numbers. Thanks in advance. Terry Do really need a space added to the number or do you want to shift the numbers a little to the right for legibility/esthetics . To add a space = " " & 12345 or = " " & A1 if your data ("12345") is in cell A1. if you want to nudge the numbers a bit to look better , use the "Increase Indent" button in the toolbar. GRth "twillett" <tgwillett@sudden...

sort equal groups of data
hi, i need a help in this, plz i got this list, id like to check the common fields (in 2 and 3 columns) like this, p.ex (so later, i could delete them, and keep and analize the other groups of data) LG-0060-0703 MT 6 LG-0060-0703 CX 6 LG-0060-0703 MT 1 LG-0060-1003 MT 6 LG-0060-1003 CX 6 LG-0060-1003 MT 1 LG-0060-1203 MT 6 LG-0060-1203 CX 6 LG-0060-1203 MT 1 LG-0060-2003 MT 6 LG-0060-2003 CX 6 LG-0060-2003 MT 1 LG-0060-3003 MT 6 LG-0060-3003 CX 6 LG-0060-3003 MT 1 LG-0060-4003 MT 6 LG-0060-4003 CX 6 LG-0060-4003 MT 1 LG-0100018 UN 1 i appreciate your help thanks Not certain what...

returning more columns with vlookup?
Hi all by default vlookup returns 1 column. Is there a way to return more than 1 (not necessarily adjacent) columns? example instead of =VLOOKUP(38, A2:L10, 3, FALSE) using something like =VLOOKUP(38, A2:L10, (3,7,9), FALSE) that would return cells in columns 3, 7 and 9 ? Thanks! Maybe not exactly what you require, but it might help you: http://www.cpearson.com/excel/TablesAndLookups.aspx Look under the heading "Returning A Row Or Column From A Table" -- Kind regards, Niek Otten Microsoft MVP - Excel "eglea" <eglea@nospam.nospam> wrote in message news:...

Entourage contact sorting
Entourage 2008 for mac. =A0I am trying to sort my contacts by category and then by last name...any thoughts? On 2010-01-22 20:39:09 -0800, shar-shar said: > Entourage 2008 for mac. �I am trying to sort my contacts by category > and then by last name...any thoughts? Unfortunately, Entourage does not allow sorting by one field and sorting within that grouping by a second field. Just one field at a time. -- Allen Watson MVP for Office (Entourage, Word) http://homepage.mac.com/allen_a_watson/ HELP for Entourage: http://entourage.mvps.org On 1/22/10 8:39 PM, in article...

How do I sort for the maximum values in each year in excel?
How do I sort data so I can see (sort?) the maximum value for each year in excel. I have 365 values per year and 78 years worth of data. I got excel to sort each year from greatest value to smallest, but now I want to sort it so each years max value is shown first, then the next years max value, etc. You would need extra help columns with formulas or using a filter if you apply auto filter and select the year from the year column and then copying the result somewhere else, then do the sorting base on the value descending. There is now way the built in sort can handle it in one fell swoop ...

Printing non-adjacent columns #3
Hi I know I can hide columns I don't want to print and I know I can use Group and Outline but that means I have to do this each time to the columns I want to print and they could be different each time in the spreadsheet - is there a quicker way using a macro or something? Basically I have 45 columns and sometimes I want to print for example A:E,G,M-P,T and sometimes I want to print other combinations of columns. Thanks Ann Record a macro when you hide your columns, print the worksheet, and unhide the columns. Then you could use that as the basis of your code to print the colu...

How do you make the labels of the columns back to letters from numbers?
For some reason, when I open a new or existing Excel file now, my Columns are labeled numbers instead of letters. How do I switch them back to letters? On 24 Mar 2007 06:16:22 -0700, cindytray@... wrote in microsoft.public.excel: >For some reason, when I open a new or existing Excel file now, my >Columns are labeled numbers instead of letters. > >How do I switch them back to letters? Menu: Tools / Options... / General / R1C1 reference style: untick -- Michael Bednarek http://mbednarek.com/ "POST NO BILLS" ...

Column grid headings
Hope somebody can help. For some reason the grid column headings on my xcel spreadsheets changed from alpha (A,B,C etc) to numeric ( 1,2,3 etc.) So now both my column and row designations are numeric. I don't know how it changed and don't know how to change back. Can anybody help? Thanks! Paula, tools, options, general, uncheck R1C1 reference style -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "paula" <pa...

Organize Rows and Columns
Hi! This is an example of what I have now GENDER COUNTRY RELIGION Male Canada Christian FIRST_NAME LAST_NAME MIDDLE_NAME DATE_OF_BIRTH ... John Smith Peter 1/1/1960 Johnny Smithson Pete 1/1/1950 John Smith Peter 1/1/1960 Johnny Smithson Pete 1/1/1950 GENDER COUNTRY RELIGION Female Canada Christian FIRST_NAME LAST_NAME MIDDLE_NAME DATE_OF_BIRTH ... Cindy Jack Antoinette 1/1/1960 Christine Smithson Pete 1/1/1950 GENDER COUNTRY RELIGION Female France Christi...

Sorting in Excel
I have a lot of data with three different groups represented by three different numbers. Is there any way to sort them by groups instead of going through by hand counting one by one? Thanks for all your help. Give us an example of the data (Don't attach any files though), showing us what you have and what you want. -- Regards Ken....................... Microsoft MVP - Excel Sys Spec - Win XP Pro / XL2K & XLXP ---------------------------------------------------------------------------- Attitude - A little thing that makes a BIG difference ----...

Report Column questions
hi to all - I have 2 questions re columns in reports (hope that's OK) a) I'd like to have 2 columns in the Detail section of my report, but only one column in one of my Group Header sections. Is this sort of thing possible? I can't seem to set it up properly. b) I have another report with 2 columns, Down, then Across (from Page Setup). The Detail section has a single row of textboxes. These are inside a Header/Footer Group using field Zone. Zone always has values 1, 2, 3, 4. Zone can also sometimes have value 5 and sometimes have value 6 as well. I need to...

ascending sort definition [sorting alphabetically]
Does ascending sort mean A-Z? Yes. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Tue, 5 Jan 2010 17:44:02 -0800, GaryBlade <GaryBlade@discussions.microsoft.com> wrote: >Does ascending sort mean A-Z? Yes. See http://www.exceltip.com/st/How_Excel_Sorts_Lists/246.html for more information. "GaryBlade" wrote: > Does ascending sort mean A-Z? ...

crosstab query column heading
I have a crosstab query and would like to change column heading. The data are "YES" ad "NO" in the table. The PIVOT clause put the "YES" and "NO" on the heading column. Is it possible to show "Met" for "YES" and "Not Met" for "NO" like "as" in s select query? Like PIVOT MyField in ("YES" as "Met", "NO" as "Not Met") Your information is great appreciated, Not directly. Create a query that changes the Yes and No answers to Met and Not Met. An II...

Sort
I have numerical data with alphabetical prefixes in a column. This is what I get when I sort: C1,C10,C2,C8,R1,R10,R11,R2 This is what I want when I sort: C1,C2,C8,C10,R1,R2,R10,R11. How can I do this? You need to extract the numbers into ahelp column and sort by the help column, if indeed you only have a letter in the string you can use =--RIGHT(A1,LEN(A1)-1) copy down, select both columns and sort by the help column -- Regards, Peo Sjoblom "Brad" <Brad@discussions.microsoft.com> wrote in message news:1A5A47FA-9AB4-4D6B-8C46-4900760A51C4@microsoft.com... > I have...

dynamically choose columns in query
I'm trying to create a query such that when the user runs it, the proper columns (fields appear). We have 12 columns, one for each month of our fiscal year (which goes from July to June). Basically, we run the query once a month. When we run it, for example in April, the months prior to April & including April (this would be July thru April), will have $0. The months after April (May and June) will have dollars. When we run this query in April, we'd rather not see each of the columns for July thru April because all the records have all $0 in those columns. Sea...

Excel columns greyed out
Please help. I received a spreadsheet from someone and they have information i which they somehow greyed out to the left. Now it is not just greye out becuase you cannot click on the cells or move the cursor into th grey area at all. You cannot even scoll past the spreadsheet the setup. They somehow prevented scrolling to the left or right. Th entire sheet is just the size of the data area. My question is. How did they do this. The sheet is not protected as unprotected it so it can't be that function. Please help. Chri -- Message posted from http://www.ExcelForum.com Hi may...

how do i use roman numerals while using word?
I need to use roman numerals in a document. How do i do it because their isn't any on the keyboard is their anywhere on the computer that i can select to use? tinkerbell_lauz <tinkerbell_lauz@discussions.microsoft.com> was very recently heard to utter: > I need to use roman numerals in a document. You just used one at the beginning of that sentence. Use the Shift key on your keyboard to get capital letters. Then use the key found in between the "u" and "o" keys to get an I, the one between "c" and "b" to get a V, the one between &q...

Using DataGrid
Hi, Is it possible to use a DataGrid control in a VBA Form. How can I link it to a sheet range and also manipulate its data? Thanks Luis ...

SORTING question
Hi. I'm using MS XP (Home) and MS Excel 2003, and I'm just learning how to use the program, so please bear with me (what follows below is a little long-winded). I recently imported a very large Access database file into Excel. This file has five columns, and one of them is a KeyID column (numbering 1 to 60,000). I will be sorting this Excel Sheet frequently, but I need to maintain the exact (original) order of the file for reasons I won't go into here. I will sort the Sheet, make some changes, then sort on the KeyID column to return to the original order (which starts a...

sort info from a row base on a single cell value
How can I sort a copy of an entire row to a seperate worksheet in the same workbook based upon a unique value in one specific cell in that row? Example: Row 2 has the number 85203 in colum C but I want to send all of the information in row 1 to sheet 2 Any ideas? Thanks! Marci Hi see: http://www.rondebruin.nl/copy5.htm -- Regards Frank Kabel Frankfurt, Germany "Marci" <anti_mtvvj03@yahoo.com> schrieb im Newsbeitrag news:233c01c4701e$49841820$a401280a@phx.gbl... > How can I sort a copy of an entire row to a seperate > worksheet in the same workbook based upon a ...

Import XML to Access ...
Hi, Under the structure of XML file. In a given file can be 1000 <MIX> ...</ MIX> in any <MIX> may be the a few to several <ingredient>. From the standpoint of the database would be to import the data into two tables 1. tblMix 2. tblIngredient (additional tables should be joined together one to many -- so that the data are connected to each other) Theoretically, it seems about to learn - but I sit a little longer (looking in the internet) .. and I can not prevail on this. Does anyone of you przerabia� import of XML to an Access VBA! ? how to deal w...

Text to Columns #10
I have a list of names that were split across 3 columns using the text to columns feature. Does anyone know of an EASY way to tell Excel to move a name into the third position if it is blank? Example: A B C 1 LastName MiddleInitial FirstName 2 Smith J Daniel 3 Taylor David 4 Pearson Tony I have thousands of records and would like to find a way to quickly move contents from the 2nd column to the 3rd IF that 3rd column is blank. Idea's anyone? Thanks! NewKid ...

Can you sort on the number of messages in thread?
Hi all, When you have your mail grouped on a field, is it then possible to sort on the number of messages in a thread. So threads with only 1 message will be on top en threads with more messages will appear lower. Hope this is possible..... All the best (this might be a solution to my previous question in another yet unanswered thread about filtering messages that are replied to) extra info: the version xp (but 2003 options are ok too) Best, Bert As far as I know, that's not an option "plurker" <nomail@nomail.com> wrote in message news:11ffe8fgqvmbc88@corp.su...

Date Math in Large Column
Hello! I have a huge spreadsheet (32000 rows). I have done a subtotal on part number. This does a sum on several other columns of values. There is a date column (B) with a date for each transaction for each part number. I am trying to come up with a way to determine the number of months over which the transactions occurred for each part number. The problem is that each subtotalled "group" is a different number of rows. I started to manually feed in this formula and then modify it for each group, but this could take days. =(max(b2:b20)-min(b2:b20))/30 This gives me ...

limiting the selection of columns within views
In addition to the option of using the attribute searchable option to determine the attributes that can be selected in an advanced find query, it would be nice if there was an option to limit the colums that can be selected by users in the option 'add columns' within views. This is especially handy for entities with lots of not used attributes. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, ...