Created
May 15, 2019 18:26
-
-
Save fergorraiz/dbf3f0a9a7ae9a9afc031ecb00eaf060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace Prueba_listview | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public void listar() | |
{ | |
string [] nombres = {"fernando","ignacio","mirta","florencia" }; | |
string[] apellidos = { "campos", "gomez", "alonso", "farinelli" }; | |
for(int num=0;num<=3;num++) | |
{ | |
ListViewItem item = new ListViewItem(); | |
item.Text = num.ToString(); | |
listView1.Items.Add(item); | |
listView1.Items[num].SubItems.Add(nombres[num]); | |
listView1.Items[num].SubItems.Add(apellidos[num]); | |
} | |
} | |
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) | |
{ | |
listView1.ListViewItemSorter = new ListViewItemComparer(1, SortOrder.Ascending); | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
listar(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace Prueba_listview | |
{ | |
public class ListViewItemComparer : System.Collections.IComparer | |
{ | |
private int col; | |
private SortOrder sortorder; | |
public ListViewItemComparer() | |
{ | |
col = 0; | |
} | |
public ListViewItemComparer(int column, SortOrder sortOder) | |
{ | |
col = column; | |
sortorder = sortOder; | |
} | |
public int Compare(object x, object y) | |
{ | |
int resultado = String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text); | |
if (sortorder == SortOrder.Ascending) | |
{ | |
return resultado; | |
} | |
else | |
{ | |
return resultado * -1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment