winform 公共控件 ListView
//数据显示,刷新
public void F5()
{
listView1.Items.Clear();
List<Students> Stu = new StudentsData().SeletAll(F1.textBox1.Text);
foreach (Students s in Stu)
{
ListViewItem li = new ListViewItem();
li.Text = s.Ids.ToString();
li.SubItems.Add(s.Code);
li.SubItems.Add(s.Name);
li.SubItems.Add(s.Sexdd);
li.SubItems.Add(s.Age.ToString());
li.SubItems.Add(s.Birthday.ToString("yyyy年MM月dd日"));
li.SubItems.Add(s.Nationna);
li.SubItems.Add(s.ClassNa);
li.SubItems.Add(s.Score.ToString());
listView1.Items.Add(li);
} }
ListView控件是一个winform自带的表格型的应用数据展示控件
好处:是功能比较完善,不需要再自己设置
缺点:不好的地方就是不能设置控件中单元格的大小,字体变大之后超出部分就会隐藏,不能直接输入内容,
要将表中的数据展示出来,需要做到以下几步:
1.先设置好ListView的列名,确定好要展示的的数据有几列
(1)如何设置列名:
点击行为属性Columns,可以设置要设置的列名(text),可以设置很多属性,基本和其他控件一致,如图:

2.查询要展示的表的内容,把这个写成一个方法,方便别的Form调用
//查询所有学生信息
public List<Students> SeletAll(string a)
{
List<Students> Stu = new List<Students>();
cmd.CommandText = "select *from Students where Adm=@a order by Ids asc";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", a);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Students s = new Students();
s.Ids = Convert.ToInt32(dr["Ids"]);
s.Code = dr["Code"].ToString();
s.Name = dr["Name"].ToString();
s.Sex = Convert.ToBoolean(dr["Sex"]);
s.Nation = dr["Nation"].ToString();
s.Birthday = Convert.ToDateTime(dr["Birthday"]);
s.Class = dr["Class"].ToString();
s.Score = Convert.ToInt32(dr["Score"]);
Stu.Add(s);
}
}
conn.Close();
return Stu;
}
3.将数据关联起来
这个写成了一个方法,方便在每次重载时调用,并能保证数据传递后调用刷新的方法
//数据显示,刷新
public void F5()
{
listView1.Items.Clear();
List<Students> Stu = new StudentsData().SeletAll(F1.textBox1.Text);
foreach (Students s in Stu)
{
ListViewItem li = new ListViewItem();
li.Text = s.Ids.ToString();
li.SubItems.Add(s.Code);
li.SubItems.Add(s.Name);
li.SubItems.Add(s.Sexdd);
li.SubItems.Add(s.Age.ToString());
li.SubItems.Add(s.Birthday.ToString("yyyy年MM月dd日"));
li.SubItems.Add(s.Nationna);
li.SubItems.Add(s.ClassNa);
li.SubItems.Add(s.Score.ToString());
listView1.Items.Add(li);
} }
4.获取选中数据的各种操作
(1)一次删除多个信息
if (listView1.CheckedItems.Count <= )
{
MessageBox.Show("请先选中学生信息!");
}
else
{
int count = ;
int Nxx = listView1.CheckedItems.Count;
List<int> Lt = new List<int>();
foreach (ListViewItem li in listView1.CheckedItems)
{
Lt.Add(Convert.ToInt32(li.Text));
}
for (int cxx = ; cxx < Nxx; cxx++)
{
if (new StudentsData().Delete(Lt[cxx], F1.textBox1.Text))
{
count++;
}
}
F5();
MessageBox.Show("学生信息删除成功,本次共删除" + count + "名学生.");
}
winform 公共控件 ListView的更多相关文章
- WinForm 公共控件
一.窗体属性: 1.AcceptButton - 窗体的“接受”按钮.如果设置该属性,每次用户按“Enter”键都相当于“单击”了该按钮. 需要设置哪个键,就在后面选择. 2.CancelButton ...
- WinForm公共控件
公共控件:1.Button:按钮 用户点击时触发事件 行为属性 Enabled -是否启用 Visible -是否隐藏2.CheckBox .CheckListBox - 复选框 复选框组 3.Com ...
- 【2017-04-25】winform公共控件、菜单和工具栏、Tab和无边框窗体制作
一.公共控件 1. Button 按钮 + 布局 - AutoSize 按钮尺寸自动适应里面内容的长度 - Location 位置 - Margin 控件与控件外边距 - S ...
- 【2017-04-25】winform公共控件、菜单和工具栏
一.公共控件 公共控件很多的属性很多都相似,这些是大部分都相同的: +布局 - AutoSize:自动适应控件上文字内容- Location:位置- Margin:控件间的间距- Size:控件大小 ...
- WinFrom 公共控件 Listview 的使用
Listview绑定数据库数据展示与操作使用 1.拖一个Listview控件到项目中先将视图改为Details 2.编辑列 设置列头 添加columnHeader成员 Text 是显示的名称 3. ...
- 公共控件Listview
ListView属性中,Items是行的总集合,Items集合中的每一个是一行,Items集合里面有ListViewItem集合,这个集合实例化:ListViewItem li=new ListVie ...
- winform 之控件ListView
使用ListView构建表格展示数据 1.添加列数据:控件ListView--上方按钮--视图(Details)--编辑列--添加 2.添加行数据:--编辑项(行)--添加 添加数据:Text:默认添 ...
- WinForm 公共控件和属性
Button 按钮 布局 AutoSize 内容超出部分是否扩展到适应尺寸大小 Location 位置坐标 Size 控件大小 行为 Enabled 控件是否启用 visible 控件 ...
- WinForm 窗体基本属性、公共控件
一.WinForm:客户端程序制作 - C/S (B/S:服务器端) 它是基于.NET Framework框架上运行,不是必须在windows系统上才能运行---------------------- ...
随机推荐
- BitmapUtil(高效压缩不失真)
package com.changim.patient.app.utils; import android.app.Activity; import android.content.ContentRe ...
- hadoop_异常_02_ExitCodeException exitCode=1: chmod: changing permissions of `/ray/hadoop/dfs/data': Operation not permitted
一.异常现象 启动hadoop时,datanode启动失败,出现如下异常: 2018-03-23 14:39:09,962 WARN org.apache.hadoop.hdfs.server.dat ...
- LeetCode OJ:Binary Tree Level Order Traversal(二叉树的层序遍历)
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- 《Effective C++》——条款08:别让异常逃离析构函数
考虑如下代码: class Widget{ public: ... ~Widget(){...}//假设这个可能吐出一个异常 }; void doSomething() { std::vector&l ...
- hdoj-1285-确定比赛名次(拓扑排序)
题目链接 /* Name:hdoj-1285-确定比赛名次 Copyright: Author: Date: 2018/4/11 15:59:18 Description: 标准的拓扑排序模板题,注意 ...
- 部署你的分布式调用链跟踪框架skywalking
使用docker-compose 一键部署你的分布式调用链跟踪框架skywalking https://www.cnblogs.com/huangxincheng/p/9666930.html 一旦你 ...
- SQL Server 索引中include
SQL Server 索引中include的魅力(具有包含性列的索引) http://www.cnblogs.com/gaizai/archive/2010/01/11/1644358.html 开文 ...
- Linux 链接网络
目录 查看网卡 存在多个网卡 网卡配置静态IP 报错总结 诚邀访问我的个人博客:我在马路边 更好的阅读体验点击查看原文:Linux链接网络 原创博客,转载请注明出处 @ Linux在安装系统结束后总要 ...
- python模型字段
http://python.usyiyi.cn/translate/django_182/ref/models/fields.html#model-field-types
- JSDoc 介绍
什么是JSDoc JSDoc是一个根据javascript文件中注释信息,生成JavaScript应用程序或库.模块的API文档 的工具.你可以使用他记录如:命名空间,类,方法,方法参数等.类似Jav ...