namereq

Untitled

Jun 12th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4.  
  5. namespace ListView
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void Form1_Shown(object sender, EventArgs e)
  15.         {
  16.             listView1.Items.Add("Data1");
  17.             listView1.Items.Add("Data2");
  18.  
  19.             List<string> dataList = new List<string>();
  20.             foreach(ListViewItem item in listView1.Items)
  21.             {
  22.                 // listView1.SelectedItems はコレクションなので
  23.                 // foreachで回して取得する。
  24.                 dataList.Add(item.Text);
  25.             }
  26.  
  27.             dataList.Reverse();
  28.  
  29.             for(int i = 0; i < listView1.Items.Count; i++)
  30.             {
  31.                 // データを逆順にする。
  32.                 listView1.Items[i].Text = dataList[i];
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment