Winform ListView根据条件定位到指定行

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Winfrom
{
public partial class Form3 : Form
{
List<string> list = null; public Form3()
{
InitializeComponent(); list = new List<string>();
} private void Form3_Load(object sender, EventArgs e)
{
listViewData.Items.Clear();
listViewData.Columns.Clear();
listViewData.Columns.Add("选择", , HorizontalAlignment.Center);
listViewData.Columns.Add("序号", , HorizontalAlignment.Right);
listViewData.Columns.Add("运单号", , HorizontalAlignment.Center); for (int i = ; i <= ; i++)
{
list.Add(i.ToString());
} foreach (var t in list)
{
var row = listViewData.Items.Count + ;
var myItem = new ListViewItem();
myItem.SubItems.Add(row.ToString());
myItem.SubItems.Add(t); if (row % == )
{
myItem.BackColor = Color.FromArgb(, , );
}
myItem.Checked = false;
listViewData.Items.Add(myItem);
}
} private void txtWaybillNumber_KeyDown(object sender, KeyEventArgs e)
{
if (string.IsNullOrEmpty(txtWaybillNumber.Text.Trim())) return;
//
int index = , i = ;
foreach (var t in list)
{
if (t == txtWaybillNumber.Text.Trim())
{
index = i;
break;
}
i++;
} listViewData.Items[index].Selected = true;
listViewData.SelectedItems[].BackColor = Color.FromArgb(, , );
listViewData.Items[index].EnsureVisible();
}
}
}

Winform ListView根据条件定位到指定行

上一篇:Linux下printf格式符%d、%lld、%llx、%u等【转自CSDN博客】


下一篇:WEB UI 整理