欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    C#中ListView控件应用实例.docx

    • 资源ID:11209179       资源大小:38.67KB        全文页数:17页
    • 资源格式: DOCX        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C#中ListView控件应用实例.docx

    1、C#中ListView控件应用实例C#中ListView控件应用实例ListView控件1 功能ListView控件可以显示带图标的项列表,用户可使用该控件创建类似Windows资源管理器的用户界面。ListView控件具有4种视图模式:(1)仅文本,这是默认视图,此视图下,只显示列表项的文本;(2)带有小图标的文本,此视图下,小图标随列表项的文本同时显示;(3)带有大图标的文本,此视图下,大图标随列表项的文本同时显示;(4)报表视图,此视图下,列表项显示在多个列中。图1为List View控件。图1 ListView 控件2属性ListView控件常用属性及说明如表1所示。表1 ListVi

    2、ew控件常用属性及说明下面对比较重要的属性进行详细介绍。(1)View属性。用于获取或设置项在控件中的显示方式。语法:public View View get; set; 属性值:View值之一。默认为LargeIcon。View的属性值及说明如表2所示。表2 View的属性值及说明(2)FullrowSelect属性。用于指定是只选择某一项,还是选择某一项所在的整行。语法:public bool FullRowSelect get; set; 属性值:如果单击某项会选择该项及其所有子项,则为True;如果单击某项仅选择项本身,则为False。默认为False。说明:除非将ListView控件

    3、的View属性设置为Details,否则FullRowSelect属性无效。在ListView显示带有许多子项的项时,通常使用FullrowSelect属性,并且,在由于控件容的水平滚动而无法看到项文本时,能够查看选定项是非常重要的。(3)GridLines属性。指定在包含控件中项及其子项的行和列之间是否显示网格线。语法:public bool GridLines get; set; 属性值:如果在项及其子项的周围绘制网格线,则为True;否则为False。默认为False。说明:除非将ListView控件的View属性设置为Details,否则GridLines属性无效。示例FullrowS

    4、elect属性本示例主要介绍View属性和FullrowSelect属性的使用方法,示例运行结果如图2所示。图2 FullrowSelect属性程序主要代码如下:this.lvStudent.View = View.Details;this.lvStudent.FullRowSelect = True;this.lvStudent.GridLines = True;完整程序代码如下:主程序文件完整程序代码using System;using System.Collections.Generic;using System.Windows.Forms;namespace _8_07static c

    5、lass Program/ / 应用程序的主入口点。/ STAThreadstatic void Main()Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new frmListView();Form1窗体设计文件完整程序代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Dra

    6、wing;using System.Text;using System.Windows.Forms;namespace _8_07public partial class Form1 : Formpublic Form1()InitializeComponent();Form1窗体代码文件完整程序代码namespace _8_07partial class Form1/ / 必需的设计器变量。/ private System.ComponentModel.IContainer components = null;/ / 清理所有正在使用的资源。/ / 如果应释放托管资源,为 true;否则为

    7、false。protected override void Dispose(bool disposing)if (disposing & (components != null)components.Dispose();base.Dispose(disposing);#region Windows 窗体设计器生成的代码/ / 设计器支持所需的方法 - 不要/ 使用代码编辑器修改此方法的容。/ private void InitializeComponent()ponents = new System.ComponentModel.Container();this.AutoScaleMode =

    8、 System.Windows.Forms.AutoScaleMode.Font;this.Text = Form1;#endregionfrmListView窗体设计文件完整程序代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace _8_07public

    9、partial class frmListView : Formpublic frmListView()InitializeComponent();private void frmListView_Load(object sender, EventArgs e)private void bntDelete_Click(object sender, EventArgs e)lvStudent.Items.Clear();private void bntAdd_Click(object sender, EventArgs e)this.lvStudent.View = View.Details;t

    10、his.lvStudent.FullRowSelect = true;SqlConnection con = new SqlConnection(server=(local);uid=sa;pwd=;database=zhy);con.Open();SqlCommand = new SqlCommand(select * from student, con);SqlDataReader dr = .ExecuteReader();this.lvStudent.Items.Clear();while (dr.Read()ListViewItem lt = new ListViewItem(dr.

    11、GetValue(0).ToString();lt.SubItems.Add(dr.GetValue(1).ToString();lt.SubItems.Add(dr.GetValue(2).ToString();this.lvStudent.Items.Add(lt);dr.Close();con.Close();this.lvStudent.Alignment = ListViewAlignment.SnapToGrid;this.lvStudent.GridLines = true;private void bntEsce_Click(object sender, EventArgs e

    12、)Application.Exit();private void label1_Click(object sender, EventArgs e)private void lvStudent_SelectedIndexChanged(object sender, EventArgs e)private void lvStudent_Click(object sender, EventArgs e)frmListView窗体代码文件完整程序代码namespace _8_07partial class frmListView/ / 必需的设计器变量。/ private System.Compone

    13、ntModel.IContainer components = null;/ / 清理所有正在使用的资源。/ / 如果应释放托管资源,为 true;否则为 false。protected override void Dispose(bool disposing)if (disposing & (components != null)components.Dispose();base.Dispose(disposing);#region Windows 窗体设计器生成的代码/ / 设计器支持所需的方法 - 不要/ 使用代码编辑器修改此方法的容。/ private void InitializeC

    14、omponent()this.lvStudent = new System.Windows.Forms.ListView();this.columnHeader1 = new System.Windows.Forms.ColumnHeader();this.columnHeader2 = new System.Windows.Forms.ColumnHeader();this.columnHeader3 = new System.Windows.Forms.ColumnHeader();this.bntAdd = new System.Windows.Forms.Button();this.b

    15、ntDelete = new System.Windows.Forms.Button();this.bntEsce = new System.Windows.Forms.Button();this.txtName = new System.Windows.Forms.TextBox();this.label1 = new System.Windows.Forms.Label();this.SuspendLayout();/ lvStudent/this.lvStudent.Columns.AddRange(new System.Windows.Forms.ColumnHeader this.c

    16、olumnHeader1,this.columnHeader2,this.columnHeader3);this.lvStudent.Location = new System.Drawing.Point(26, 32);this.lvStudent.Name = lvStudent;this.lvStudent.Size = new System.Drawing.Size(352, 114);this.lvStudent.TabIndex = 0;this.lvStudent.UseCompatibleStateImageBehavior = false;this.lvStudent.Vie

    17、w = System.Windows.Forms.View.Details;this.lvStudent.SelectedIndexChanged += new System.EventHandler(this.lvStudent_SelectedIndexChanged);this.lvStudent.Click += new System.EventHandler(this.lvStudent_Click);/ columnHeader1/this.columnHeader1.Text = 学号;this.columnHeader1.Width = 97;/ columnHeader2/t

    18、his.columnHeader2.Text = 学生姓名;this.columnHeader2.Width = 136;/ columnHeader3/this.columnHeader3.Text = 学生班级;this.columnHeader3.Width = 118;/ bntAdd/this.bntAdd.Location = new System.Drawing.Point(26, 171);this.bntAdd.Name = bntAdd;this.bntAdd.Size = new System.Drawing.Size(75, 23);this.bntAdd.TabInd

    19、ex = 2;this.bntAdd.Text = 加截(&F);this.bntAdd.UseVisualStyleBackColor = true;this.bntAdd.Click += new System.EventHandler(this.bntAdd_Click);/ bntDelete/this.bntDelete.Location = new System.Drawing.Point(159, 171);this.bntDelete.Name = bntDelete;this.bntDelete.Size = new System.Drawing.Size(75, 23);t

    20、his.bntDelete.TabIndex = 3;this.bntDelete.Text = 清除(&G);this.bntDelete.UseVisualStyleBackColor = true;this.bntDelete.Click += new System.EventHandler(this.bntDelete_Click);/ bntEsce/this.bntEsce.Location = new System.Drawing.Point(303, 171);this.bntEsce.Name = bntEsce;this.bntEsce.Size = new System.

    21、Drawing.Size(75, 23);this.bntEsce.TabIndex = 4;this.bntEsce.Text = 退出(&T);this.bntEsce.UseVisualStyleBackColor = true;this.bntEsce.Click += new System.EventHandler(this.bntEsce_Click);/ txtName/this.txtName.Location = new System.Drawing.Point(159, 209);this.txtName.Name = txtName;this.txtName.Size =

    22、 new System.Drawing.Size(116, 21);this.txtName.TabIndex = 5;/ label1/this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(73, 212);this.label1.Name = label1;this.label1.Size = new System.Drawing.Size(59, 12);this.label1.TabIndex = 6;this.label1.Text = 学生姓名:;this.label1.Click +

    23、= new System.EventHandler(this.label1_Click);/ frmListView/this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(418, 266);this.Controls.Add(this.label1);this.Controls.Add(this.txtName);this

    24、.Controls.Add(this.bntEsce);this.Controls.Add(this.bntDelete);this.Controls.Add(this.bntAdd);this.Controls.Add(this.lvStudent);this.Name = frmListView;this.Text = frmListView;this.Load += new System.EventHandler(this.frmListView_Load);this.ResumeLayout(false);this.PerformLayout();#endregionprivate S

    25、ystem.Windows.Forms.ListView lvStudent;private System.Windows.Forms.Button bntAdd;private System.Windows.Forms.Button bntDelete;private System.Windows.Forms.Button bntEsce;private System.Windows.Forms.ColumnHeader columnHeader1;private System.Windows.Forms.ColumnHeader columnHeader2;private System.W

    26、indows.Forms.ColumnHeader columnHeader3;private System.Windows.Forms.TextBox txtName;private System.Windows.Forms.Label label1;3方法(1)HitTest方法。该方法在给定x和y坐标的情况下,提供项信息。(2)Clear方法。该方法用于删除ListView控件中所有的项。语法:public void Clear ()例如,下面删除名称为lvStudent的ListView控件的所有项:lvStudent.Items.Clear();4事件(1)ItemCheck事件。该

    27、事件在选中ListView控件项时触发此事件。(2)Click事件。该事件在单击ListView控件列时触发。语法:public event EventHandler Click示例Click事件的使用本示例实现效果为,当程序运行时,单击【ListView】按钮,将姓名显示在文本框中。示例运行结果如图3所示。图3 Click事件的使用程序主要代码如下:private void lvStudent_Click(object sender, EventArgs e)this.txtName.Text = lvStudent.SelectedItems0.SubItems1.Text;完整程序代码如

    28、下:主程序文件完整程序代码using System;using System.Collections.Generic;using System.Windows.Forms;namespace _8_07static class Program/ / 应用程序的主入口点。/ STAThreadstatic void Main()Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new frmListView();Form1窗体设计文件完整程序代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace _8_07public partial class Form1 : Formpublic Form1()InitializeComponent();Form1窗体代码文件完整程序代码


    注意事项

    本文(C#中ListView控件应用实例.docx)为本站会员主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1

    收起
    展开