| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 423 人关注过本帖
标题:关于Listview应用问题
只看楼主 加入收藏
chenyongsong
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-12-26
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
关于Listview应用问题
新手仿书示例,用ListView控件显示:C:\WINDOWS 下文件及文件夹,并根据视图通过单选按钮切换不同模式,但不能实现,请高手赐教,原程序如下:

using System;
using System.Collections.Generic;
using
using System.Data;
图片附件: 游客没有浏览图片的权限,请 登录注册

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using

namespace Example_ListViewTest1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radSmallIco.Checked)
                this.lvwFile.View = View.SmallIcon;
        }
        private void CreateColumnHeader()
        {
            System.Windows.Forms.ColumnHeader header;
            header = new ColumnHeader();
            header.Text = "名称";
            this.lvwFile.Columns.Add(header );
            header = new ColumnHeader();
            header.Text = "大小";
            this.lvwFile.Columns.Add(header);
            header = new ColumnHeader();
            header.Text = "修改日期";
            this.lvwFile.Columns.Add(header);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateColumnHeader();
            try {
                ListViewItem lstItem;
                ListViewItem.ListViewSubItem lstSubItem;
                DirectoryInfo dir = new DirectoryInfo("c:\\windows");
                DirectoryInfo[] dirs = dir.GetDirectories();
                FileInfo[] files = dir.GetFiles();
                this.lblCurrentPath.Text = "c:\\WINDOWS";
                foreach (DirectoryInfo di in dirs )
                {
                this .lvwFile .BeginUpdate();
                lstItem = new ListViewItem();
                lstItem.Text = di.Name;
                lstItem.Tag = di.FullName;
                lstItem.ImageIndex = 0;
                lstSubItem = new ListViewItem.ListViewSubItem();
                lstSubItem.Text = "";
                lstItem.SubItems.Add(lstSubItem);
                lstSubItem = new ListViewItem.ListViewSubItem();
                lstSubItem.Text = di.LastAccessTime.ToString();
                lstItem.SubItems.Add(lstSubItem);
                this.lvwFile.Items.Add(lstItem);
                    foreach (FileInfo fi in files )
                    {
                        lstItem = new ListViewItem();
                        lstItem.Text = fi.Name;
                        lstItem.Tag = fi.FullName;
                        lstItem.ImageIndex = 1;
                        lstSubItem = new ListViewItem.ListViewSubItem();
                        lstSubItem.Text = fi.Length.ToString();
                        lstItem.SubItems.Add(lstSubItem);
                        lstSubItem = new ListViewItem.ListViewSubItem();
                        lstSubItem.Text = fi.LastAccessTime.ToString();
                        lstItem.SubItems.Add(lstSubItem);
                        this.lvwFile.Items.Add(lstItem );
                    }
                }

                this.lvwFile.EndUpdate();
              }
            catch(Exception ex)
            {
             MessageBox.Show(ex.Message );
            }
         }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void radDetail_CheckedChanged(object sender, EventArgs e)
        {
            if (radDetail.Checked)
                this.lvwFile.View = View.Details;
        }

        private void radlist_CheckedChanged(object sender, EventArgs e)
        {
            if (radlist.Checked)
                this.lvwFile.View = View.List;
        }

        private void radLargeIcon_CheckedChanged(object sender, EventArgs e)
        {
            if (radLargeIcon.Checked)
            {
                this.lvwFile.View = View.LargeIcon;
            }
        }

        private void radTitle_CheckedChanged(object sender, EventArgs e)
        {
            if (radTitle.Checked)
                this.lvwFile.View = View.Tile;
        }

      
    }
}
搜索更多相关主题的帖子: 文件夹 
2010-12-26 19:28
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
还是把你的工程发上来吧~
2010-12-26 19:49
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:5 
楼上前几天的那个listview做的很好,你可以看看;

当然发工程上来楼上可以帮你改改了?!!哈哈
2010-12-26 20:18
chenyongsong
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-12-26
收藏
得分:0 
好的,项目我打包发上来,帮忙看看错在哪里了?

Example_ListViewTest1.rar (54.66 KB)
2010-12-26 20:42
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:15 
 this .lvwFile .BeginUpdate();
这一行放到foreach循环外面。

详情请看一下MSDN:ListView.BeginUpdate的用法。
2010-12-26 21:27
chenyongsong
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-12-26
收藏
得分:0 
回复 5楼 zhoufeng1988
多谢版主,显示问题解决了!
2010-12-26 21:52
快速回复:关于Listview应用问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031786 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved