zoukankan      html  css  js  c++  java
  • c#中listview控件添加信息例程

    折腾了打扮下午,才搞明白了listview的所以然,记得在大学的时候给外教做过一个项目中,用到了listview这个控件,但是那是在vb中,和C#的使用还是稍微有点差别,书上介绍的也不多,网上写的也乱七八糟。

    下面就通过一个小示例解释一下:

    加入想在listview中加入以下两条信息。

    通过设计模式添加很简单,这里就不说了,我们通过代码来完成。

    //设置listview控件
                //MessageBox.Show(listView1.Columns.Count.ToString ());//用于说明一共有多少列
                listView1.View = View.Details;// Set the view to show details.有的时候,如果不设置这个,那么即使你再设计模式下添加了列,运行的时候也不会显示,这里我们用命令控制他显示,当然,我们也可以设计模式下的view属性选择Details.

                listView1.LabelEdit = true;// Allow the user to edit item text.允许用户修改值。
                //listView1.AllowColumnReorder = true;//Allow the user to rearrange columns.
                // Display grid lines.
                listView1.GridLines = true;//显示网格线
                // Sort the items in the list in ascending order.
               // listView1.Sorting = SortOrder.Ascending;

                // Create columns for the items and subitems.

    //一共三行            listView1.Columns.Add("name");
                listView1.Columns.Add("age");
                listView1.Columns.Add("rollno");
                ListViewItem firstrecord = new ListViewItem("hope");//这个是第一行第一列
                firstrecord.SubItems.Add("22");//第一行第二列
                firstrecord.SubItems.Add("1001");//第一行第三列
                ListViewItem secondrecord = new ListViewItem("basil");//这个是第二行第一列
                secondrecord.SubItems.Add("23");//第二行第二列
                secondrecord.SubItems.Add("1002");//第二行第三列
                listView1.Items.Add(firstrecord);//把第一行添加上
                listView1.Items.Add(secondrecord);//把第二行添加上

  • 相关阅读:
    【华为云技术分享】ArcFace简介
    [学]PHP爬虫框架phpspider
    zend studio 自动注释、备注和常用有用快捷键
    mysql 为什么加了排序字段后不会自动按ID升序排序?
    【PHP转义字符】单引号双引号以及转义字符【原创】
    Javascript小结(四)----包装对象
    JavaScript小结(三)----字符串操作
    JavaScript小结(二)-----Date()函数
    Javascript小结(一)----prototype对象
    PHP底层原理分析和底层扩展编写
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668400.html
Copyright © 2011-2022 走看看