Home > Back-end >  ListView - unable to make 2 columns
ListView - unable to make 2 columns

Time:09-21

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;
                }
            }
        }
    }
}

The problem is that when the first time is added, everything is fine, but I realized that they stick to the screen, after the next iteration, they no longer appear progressbars, or somewhere below in a bunch in 1 place, as if it were there 1, and the paths to the files themselves are displayed as needed.

The problem is probably due to pb.SetBounds, since ListView has a scrollbar, scrolling and everything collapses, maybe someone will tell you how to solve such a problem?

I need the file address on the left, and the progress bar on the right, nothing else is needed.
Each time the function should take no more than Max.
That is, only Max or less can be processed at a time.

CodePudding user response:

It was possible to solve without ListView, through TableLayoutPanel.

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);
  • Related