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. Springboot中对Service层进行集成测试时注意点

    @SpringBootTest(classes = {DataSourceAutoConfiguration.class,MybatisAutoConfiguration.class,****Impl ...

  2. python的socke编程

    python的sock编程分为TCP编程和UDP编程,两者不同在于,TCP需要首先建立连接才能发送接收数据,而UDP则可以直接发送接收不需要预先建立连接. tcp编程,我总结为4步 TCP的serve ...

  3. XproerIM2-更新-2017-6-28

    资源下载:源代码,开发文档,客户端,openfire-3.9.3.exe,openfire-4.1.4.exe, 开源库:cximage600-full,boost-1.55.0,pugixml-1. ...

  4. CPU TFLOPS 计算

    CPU TFLOPS 计算 姚伟峰 yaoweifeng0301@126.com] http://www.cnblogs.com/Matrix_Yao/ 深度学习任务是一个计算密集型任务,所以很关注计 ...

  5. Docker Got permission denied while trying to connect to the Docker daemon socket at unix://

    这是没有权限的原因,先将自己加入docker组,然后在重新启动就可以了, 下面参考来源:https://blog.csdn.net/weixin_40896352/article/details/80 ...

  6. Homework:奇偶性

    // 程序功能: // 要求用户从键盘输入一个整数,判断其是奇数还是偶数 #include <stdio.h> int main() { int x; printf("输入一个整 ...

  7. VMware要不要装在固态SSD上,虚拟机系统文件要不要放固态SSD上,虚拟机伤不伤固态SSD

    先说结论:VMware建议装在固态上运行快,系统文件最好放在机械硬盘上(有钱除外),虚拟机会伤固态. 今天在学淘淘商城中的搜索项目,克隆了一个虚拟机,这个虚拟机开机贼慢,令人无法忍受,我觉得我再也受不 ...

  8. Windows+Apache+mod_wsgi+Flask部署方法

    环境:windows7 64bit 1.python版本3.6.5,32位 2.下载Apache,版本httpd-2.4.33-o102o-x86-vc14-r2,32位,vc14编译 3.下载mod ...

  9. linux 安装 kafka&zookeeper

    安装kafka 1,下载kafka. #cd /usr/local #wget wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.1.1 ...

  10. get() got an unexpected keyword argument

    TypeError: get() got an unexpected keyword argument 'news_id'ERROR basehttp 154 "GET /news/3/ H ...