zoukankan      html  css  js  c++  java
  • 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("选择", 40, HorizontalAlignment.Center);
                listViewData.Columns.Add("序号", 40, HorizontalAlignment.Right);
                listViewData.Columns.Add("运单号", 120, HorizontalAlignment.Center);
    
                for (int i = 1; i <= 30; i++)
                {
                    list.Add(i.ToString());
                }
    
                foreach (var t in list)
                {
                    var row = listViewData.Items.Count + 1;
                    var myItem = new ListViewItem();
                    myItem.SubItems.Add(row.ToString());
                    myItem.SubItems.Add(t);
    
                    if (row % 2 == 0)
                    {
                        myItem.BackColor = Color.FromArgb(252, 254, 215);
                    }
                    myItem.Checked = false;
                    listViewData.Items.Add(myItem);
                }
            }
    
            private void txtWaybillNumber_KeyDown(object sender, KeyEventArgs e)
            {
                if (string.IsNullOrEmpty(txtWaybillNumber.Text.Trim())) return;
                //30
                int index = 0, i = 0;
                foreach (var t in list)
                {
                    if (t == txtWaybillNumber.Text.Trim())
                    {
                        index = i;
                        break;
                    }
                    i++;
                }
    
                listViewData.Items[index].Selected = true;
                listViewData.SelectedItems[0].BackColor = Color.FromArgb(49, 106, 197); 
                listViewData.Items[index].EnsureVisible();
            }
        }
    }

  • 相关阅读:
    定时器的实现
    派遣函数
    IRP的同步
    duilib基本流程
    驱动程序的同步处理
    WFP在包含fwpmu.h头的时候出错
    自己写的驱动用CreateFile打开时错误码返回1的问题
    Windows内核函数
    16_会话技术_Session
    15_会话技术_Cookie
  • 原文地址:https://www.cnblogs.com/xiaoqi742709106/p/5032313.html
Copyright © 2011-2022 走看看