3 Replies - 598 Views - Last Post: 27 April 2014 - 04:22 PM Rate Topic: -----

#1 Noboey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-August 13

Sorting a ListView

Posted 22 April 2014 - 02:16 PM

Dear readers,

at the moment I lack access to the pc with the code on it, so for now I will try to keep my question basic.
if anyone thinks more information will make the question cleared, I will upload it when I have access again.

now here is my problem:
I have a listview witch is populated by user input(lets say for the ease of argument that the input is "first-name" "last-name" and "e-mail adres") all of with get there information from textboxes.
then all the information gets stored in a list and on closing that list is stored in a xml-file in the following format

<Root>
<Data>
<first-name>
Samual
</first-name>
<last-name>
Hunter
</last-name>
<e-mail adres>
arandomemail@domain.com
</e-mail adres>
</Data>
<Data>
<first-name>
John
</first-name>
<last-name>
Doe
</last-name>
<e-mail adres>
anothermail@domain.com
</e-mail adres>
</Data>
</Root>



the input, saving and loading is no problem. when you open the file this listview is in view = List so that you only see the last-name(I prefer it that way since I know how to code that) and when you click it it fills the textboxes with the corresponding information.

what I am trying to figure out it how to make it that it sorts itself(preferred sorting when something is changed).
I tried the ListView.sorting = SortOrder.Ascending; when I do it that way it messes up the corresponding information(is it clear what I mean or do I need to add an example).
with the help of google I couldnt find something that I could understand, so and help or links to possible tutorials would be much appreciated.

Greetings,
Hunter

Is This A Good Question/Topic? 0
  • +

Replies To: Sorting a ListView

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Sorting a ListView

Posted 22 April 2014 - 06:50 PM

When you tell it to sort it used the default Comparer on your class that you've bound to the control. Overload the Comparer to specify the sort you want.

Post your class that is holding the data and I'll see if I can help you.

There is an example at http://msdn.microsof...=vs.110%29.aspx if you want to go it alone :)

This post has been edited by Momerath: 22 April 2014 - 06:51 PM

Was This Post Helpful? 0
  • +
  • -

#3 Noboey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-August 13

Re: Sorting a ListView

Posted 23 April 2014 - 12:33 PM

if you would help me I would really like that.
I can post the class witch handles the data, I aint sure this is what you need/mean so if there is more date you need I could email you the entire solution, well, before we get to that here is what I think you mean by the class that holds the data.
now that I have some more time I will explain what my program does, instead of storing names and emails, it stores a the name of a tv show with data(Season, Episode, etc)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyEpisodeCounter
{
    public class Info
    {
        public string FileLocation
        {
            get;
            set;
        }
        public string Serie
        {
            get;
            set;
        }
        public string Season
        {
            get;
            set;
        }
        public string Episode
        {
            get;
            set;
        }
        public string AirDay
        {
            get;
            set;
        }
        public string Status
        {
            get;
            set;
        }
        public DateTime ReturnsOn
        {
            get;
            set;
        }
    }
}



FileLocation is a string in a file located in AppData/Roaming witch points to the file where the users saves the information about the serie's.

upon saving it deletes the data in the file and replaces it with the list<> from the form(witch on loading loads from that file) not sure if it is the best way but it was the only way I could think of to avoid duplicate entry's.
Was This Post Helpful? 0
  • +
  • -

#4 Noboey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-August 13

Re: Sorting a ListView

Posted 27 April 2014 - 04:22 PM

alright, tried to understand the link you send but I am walking into some walls.
just to question if I am on the right path, for what I understand I need to make a new class witch extends the IComparer in a way similar to class newClass : IComparer<list>. And then fill that class with the code to compare the listview entry's, and then bind that to an event (like a button or something).
Is that a correct?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1