首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListView -无法生成2列

ListView -无法生成2列
EN

Stack Overflow用户
提问于 2022-09-18 10:02:46
回答 1查看 36关注 0票数 1
代码语言:javascript
复制
using Iterateds.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace Iterateds {
    public partial class Main : Form {
        public static readonly int Max = 10;
        public static List<string> Files = new List<string>();
        public static int CountFiles = 0,
                          Threaded = 0,
                          Counters = 0;
        public Main() {
            string File;
            StringReader strReader = new StringReader(Resources.files.Trim());
            while (null != (File = strReader.ReadLine())) {
                Files.Add(File);
            }
            CountFiles = Files.Count;
            InitializeComponent();
        }
        
        public void Iterated() {
            if (0 >= Files.Count) {
                return;
            }
            string selectPath = this.selectPath?.Text;
            if (string.IsNullOrEmpty(selectPath.Trim())) {
                return;
            }
            int Counter = 0;
            foreach (string file in Files) {
                if (Main.Counters >= Counter) {
                    ++Counter;
                    continue;
                }
                if (Max > Threaded) {
                    string filed = file.Trim();
                    if (string.IsNullOrEmpty(filed)) {
                        continue;
                    }                    
                    // -----------------------------------------------
                    // -----------------------------------------------
                    // -----------------------------------------------
                    //////////////////////////
                    // THE PROBLEM IS HERE: //
                    //////////////////////////
                        ListViewItem item = new ListViewItem(filed);
                        ProgressBar pb = new ProgressBar {
                            Maximum = 100
                        };
                        this.Logs.Items.Add(item);
                        Rectangle r = item.Bounds;
                        pb.SetBounds(r.X, r.Y, r.Width, r.Height);
                        this.Logs.Controls.Add(pb);
                    ///////////////////////////////
                    // ^^ THE PROBLEM IS HERE ^^ //
                    ///////////////////////////////
                    // -----------------------------------------------
                    // -----------------------------------------------
                    // -----------------------------------------------
                    // here is the load manager, after we reach "Threaded" it starts "Iterated" again to take another "Max" or the remainder if less.
                    ++Threaded;
                }
            }
        }
    }
}

问题是,当第一次添加时,一切都很好,但是我意识到它们坚持在屏幕上,在下一次迭代之后,它们不再出现在进度条上,或者出现在一个位置下面的某个地方,就好像它就在1,并且文件本身的路径会根据需要显示出来。

这个问题可能是由pb.SetBounds引起的,因为ListView有一个滚动条,滚动和所有东西都会崩溃,也许有人会告诉你如何解决这个问题?

我需要左边的文件地址,右边的进度条,不需要其他任何东西。

每次函数都不应该超过Max

也就是说,一次只能处理Max或更少的文件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-18 14:45:06

没有ListView就有可能通过TableLayoutPanel解决问题。

代码语言:javascript
复制
this.tableLayoutPanel1.RowCount += 1;
Label txt = new Label {
    Text = filed
};
txt.AutoSize = true;
ProgressBar pb = new ProgressBar {
    Maximum = 100
};
pb.Height = 10;
this.tableLayoutPanel1.Controls.Add(txt);
this.tableLayoutPanel1.Controls.Add(pb);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73761779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档