2020年1月9日 17:50:55
附件
https://files.cnblogs.com/files/xe2011/ListBoxSort.rar
这种方法 如果内容足够多就能看到滚动条闪烁了,我觉得这是列表框清除内容,再添加内容引起的。
用不删除列表,重新赋值的方法能解释闪烁,但过程时间又太长。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ListBoxDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<string> array = new List<string>(); //初始化 private void Form1_Load(object sender, EventArgs e) { string[] arr = { "a.m.", "a", "Smith", "Jones", "module", "zoology", "youth", "Hsieh", "abdomen", "Xerox", "season", "Luncheon", "transferable","macro","genuine" }; array.AddRange(arr); listBox1.DataSource = array; } private void button升序_Click(object sender,EventArgs e) { //lambda var a = array.OrderBy(c => SortOrder.Ascending).ToArray(); //linq //var a = from x in array orderby x ascending select x; listBox1.DataSource =a; } private void button降序_Click(object sender,EventArgs e) { //lambda var b = array.OrderBy(c => SortOrder.Descending).Reverse().ToArray(); //linq //var a = from x in array orderby x descending select x; listBox1.DataSource = b; } private void button乱序_Click(object sender,EventArgs e) { //lambda //var a = array.OrderBy(c => Guid.NewGuid()).ToArray(); //linq var a = from x in array orderby Guid.NewGuid() select x; listBox1.DataSource = a.ToArray(); } } }
原文地址:https://www.cnblogs.com/xe2011/p/12172776.html
时间: 2024-10-13 10:43:17