C#  ListView应用

1. 添加表头标题的方法

a. 直接在ListView控件上编写

b. 通过代码编写

             //动态添加lstv_ReaderList列表头
/*
lstv_ReaderList.Columns.Add("序号", 50, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("读写器IP", 90, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("读写器Port", 75, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("本机Port", 75, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("通讯方式", 75, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("参数配置", 80, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("连接操作", 80, HorizontalAlignment.Center);
lstv_ReaderList.Columns.Add("运行操作", 80, HorizontalAlignment.Center);
*/

2. 在表格中插入控件的方法

a. 直接通过代码进行添加

                 //参数配置
myitem.SubItems.Add("更新参数");
Button btn_SetParam = new Button();
btn_SetParam.Text = "更新参数";
btn_SetParam.Enabled = false;
btn_SetParam.BackColor = Color.Bisque;
btn_SetParam.Click += lstv_ReaderList_SetParam_Click;
lstv_ReaderList.Controls.Add(btn_SetParam);
btn_SetParam.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
btn_SetParam.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top); //连接操作
myitem.SubItems.Add("打开连接");
Button btn_Connect = new Button();
btn_Connect.Text = "打开连接";
btn_Connect.BackColor = Color.Bisque;
btn_Connect.Click += lstv_ReaderList_btnConnect_Click;
lstv_ReaderList.Controls.Add(btn_Connect);
btn_Connect.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
btn_Connect.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top); //运行操作
myitem.SubItems.Add("开启运行");
Button btn_Run = new Button();
btn_Run.Text = "开启运行";
btn_Run.BackColor = Color.Bisque;
btn_Run.Click += lstv_ReaderList_btnRun_Click;
lstv_ReaderList.Controls.Add(btn_Run);
btn_Run.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
btn_Run.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top);

b. 通过构建List<类>,在类中构建控件:

 类:
class ReaderControl
{
public Button btn_ReaderParam; //设置读写器参数按钮
public Button btn_ReaderConect; //设置读写器连接按钮
public Button btn_ReaderRun; //设置读写器运行按钮 }
//参数配置
myitem.SubItems.Add("更新参数");
readercontrol.btn_ReaderParam = new Button();
readercontrol.btn_ReaderParam.Text = "更新参数";
readercontrol.btn_ReaderParam.Enabled = false;
readercontrol.btn_ReaderParam.BackColor = Color.Bisque;
readercontrol.btn_ReaderParam.Click += lstv_ReaderList_SetParam_Click;
lstv_ReaderList.Controls.Add(readercontrol.btn_ReaderParam);
readercontrol.btn_ReaderParam.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
readercontrol.btn_ReaderParam.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top); //连接操作
myitem.SubItems.Add("打开连接");
readercontrol.btn_ReaderConect = new Button();
readercontrol.btn_ReaderConect.Text = "打开连接";
readercontrol.btn_ReaderConect.BackColor = Color.Bisque;
readercontrol.btn_ReaderConect.Click += lstv_ReaderList_btnConnect_Click;
lstv_ReaderList.Controls.Add(readercontrol.btn_ReaderConect);
readercontrol.btn_ReaderConect.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
readercontrol.btn_ReaderConect.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top); //运行操作
myitem.SubItems.Add("开启运行");
readercontrol.btn_ReaderRun = new Button();
readercontrol.btn_ReaderRun.Text = "开启运行";
readercontrol.btn_ReaderRun.BackColor = Color.Bisque;
readercontrol.btn_ReaderRun.Click += lstv_ReaderList_btnRun_Click;
lstv_ReaderList.Controls.Add(readercontrol.btn_ReaderRun);
readercontrol.btn_ReaderRun.Size = new Size(lstv_ReaderList.Items[row].SubItems[].Bounds.Width,
lstv_ReaderList.Items[row].SubItems[].Bounds.Height);
readercontrol.btn_ReaderRun.Location = new Point(lstv_ReaderList.Items[row].SubItems[].Bounds.Left, lstv_ReaderList.Items[row].SubItems[].Bounds.Top);

2. 在表格中插入控件调用方法

a.  直接通过代码的调用方法,通过控件位置进行匹配:

         private void lstv_ReaderList_btnConnect_Click(object sender, EventArgs e)
{
int btn_num = lstv_ReaderList.Controls.Count;
for (int i = ; i < btn_num; i++)
{
Button btn = (Button)lstv_ReaderList.Controls[i];
if (((Button)sender).Location == btn.Location)
{
int btn_index = i / ;
//连接操作
if (list_ReaderControl[btn_index].byte_ConnectState == )
{
Reader_Connect(btn, btn_index, );
}
else
{
Reader_Disconnect(btn, btn_index, );
}
}
}
}

b.  直接通过List<类>调用方法:

         private void lstv_ReaderList_btnConnect_Click(object sender, EventArgs e)
{
for (int i = ; i < lstv_ReaderList.Items.Count; i++)
{
if (((Button)sender).Location == list_ReaderControl[i].btn_ReaderConect.Location)
{
//连接操作
if (list_ReaderControl[i].byte_ConnectState == )
{
Reader_Connect(i);
}
else
{
Reader_Disconnect(i);
}
}
}
}

C# ListView应用的更多相关文章

  1. 张高兴的 UWP 开发笔记:横向 ListView

    ListView 默认的排列方向是纵向 ( Orientation="Vertical" ) ,但如果我们需要横向显示的 ListView 怎么办? Blend for Visua ...

  2. Android—万能ListView适配器

    ListView是开发中最常用的控件了,但是总是会写重复的代码,浪费时间又没有意义. 最近参考一些资料,发现一个万能ListView适配器,代码量少,节省时间,总结一下分享给大家. 首先有一个自定义的 ...

  3. Android—ListView条目背景为图片时,条目间距问题解决

    ListView是android开发中使用最普遍的控件了,可有的listView条目的内容颇为丰富,甚至为了美观,背景用指定图片,如下图:

  4. Android中ListView实现图文并列并且自定义分割线(完善仿微信APP)

    昨天的(今天凌晨)的博文<Android中Fragment和ViewPager那点事儿>中,我们通过使用Fragment和ViewPager模仿实现了微信的布局框架.今天我们来通过使用Li ...

  5. listview下拉刷新和上拉加载更多的多种实现方案

    listview经常结合下来刷新和上拉加载更多使用,本文总结了三种常用到的方案分别作出说明. 方案一:添加头布局和脚布局        android系统为listview提供了addfootview ...

  6. Android listview和gridview以及view的区别

    GridView 可以指定显示的条目的列数. listview一般显示的条目的列数都是一列 如果是列表(单列多行形式)的使用ListView,如果是多行多列网状形式的优先使用GridView andr ...

  7. mono for android Listview 里面按钮 view Button click 注册方法 并且传值给其他Activity 主要是context

    需求:为Listview的Item里面的按钮Button添加一个事件,单击按钮时通过事件传值并跳转到新的页面. 环境:mono 效果: 布局代码 主布局 <?xml version=" ...

  8. 【腾讯Bugly干货分享】跨平台 ListView 性能优化

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/FbiSLPxFdGqJ00WgpJ94yw 导语 精 ...

  9. android内部培训视频_第三节(3)_常用控件(ViewPager、日期时间相关、ListView)

    第三节(2):常用控件之ViewPager.日期时间相关.ListView  一.ViewPager 实例:结合PagerAdapter滑动切换图片  二.日期时间相关:AnalogClock\Dig ...

  10. 父ListView嵌套子ListView时点击事件没有响应

    转发请备注出处:http://www.cnblogs.com/LT5505/p/5972999.html 问题: 在ListView中嵌套ListView之后,子ListView会把父ListView ...

随机推荐

  1. idea的maven搭建

    IntelliJ IDEA中创建Web聚合项目(Maven多模块项目) 在file-setting-maven中可以配置自己下载的maven,在自己下载maven目录的config下的setting. ...

  2. bootstrap学习1

    1.form-control -宽度变成了100% -设置了一个浅灰色(#ccc)的边框 -具有4px的圆角 -设置阴影效果,并且元素得到焦点之时,阴影和边框效果会有所变化 -设置了placehold ...

  3. vmware 进入虚拟机VMware的系统后鼠标不能点

    vmware 进入虚拟机VMware的系统后鼠标不能点 1)关闭虚拟机,重启win10,再打开虚拟机好了 2)

  4. python3字典练习(重要)

    #keys()返回字典里的所有的键dic = {'k1':'wcj','k2':33,'k3':[11,22,33,]}r = dic.keys()print(r) #结果为ict_keys(['k3 ...

  5. lnmp环境部署脚本-y

    系统环境:centos6.X #!/bin/bash#date:2018-01-01## MySQL 安装8版本的话不太适合,有待于添加安装脚本进行测试#新版的MySQL安装需要高版本2.8以上cma ...

  6. ArcGIS 图层旋转工具-arcgis案例实习教程

    ArcGIS 图层旋转工具-arcgis案例实习教程 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:对输入图层执行坐标旋转 使用方法:输入图层,旋转中心,旋转 ...

  7. Spring Boot与Docker部署

    开启Docker远程访问 首先需要开启docker远程访问功能,以便可以进行远程操作. CentOS 6 修改/etc/default/docker文件,重启后生效(service docker re ...

  8. 简单搭建一个SpringBoot

    1.SpringBoot下载 https://start.spring.io/ 选择工程类型,编译语言,版本,工程名称,需要支持组件等:选择好了以后点击生成项目. 之后会下载一个压缩文件,解压之后导入 ...

  9. Set集合特点

    1,无序(存储和读取的顺序可能不一样) 2,不允许重复(要求元素唯一) 3,无索引

  10. Jmeter Dash Report(HTML Report)删除Hits Per Second graph的方法

    通过命令行 Non GUI的方式执行jmeter的jmx脚本可以生成HTML Report(Dash Report). 这个report默认自带了很多种图表报告,比如statistics,Over t ...