L
L
Leonid2020-09-07 21:17:43
C++ / C#
Leonid, 2020-09-07 21:17:43

How to add ListView column content to variable list?

Good afternoon,
I load a list of addresses from a text file into the program line by line

private void AddIPMassConfig_btn_Click(object sender, EventArgs e)
        {
            OpenFileDialog OpenDialog = new OpenFileDialog();
            OpenDialog.Title = "Open IP List File";
            OpenDialog.Filter = "text files|*.txt";
            if (OpenDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string line in File.ReadAllLines(OpenDialog.FileName, Encoding.ASCII))
                   MassConfigIPList.Items.Add(new ListViewItem(line));
                IPaddCount_label.Text = MassConfigIPList.Items.Count.ToString();               

            }

Each row is entered into the ListView for further processing (checking the availability of the ICMP request).

How can I make all addresses in a column variable so that we can work with them one by one? It turns out only for one cell ((((
!!!! string[] Hosts = MassConfigIPList.Items.AddRange(MassConfigIPList.Items());
        
            Hosts.Add(MassConfigIPList.Items[2].Text);
            Hosts.Add(MassConfigIPList.Items[3].Text);
            
            foreach (string Host in Hosts)
            //foreach (string line in MassConfigIPList.Items)
            {
                //string Host = MassConfigIPList.FocusedItem.SubItems[0].Text;
                //byte[] buffer = Encoding.ASCII.GetBytes(Host);
                //pingReply = switchPing.Send(Host, timeout, buffer, options);

                if (pingReply.Status == IPStatus.Success)
                {
                    MassConfigIPList.Items[0].SubItems.Add("Ok");
                    //LiveCount_label.Text = LiveList.Items.Count.ToString();
                }
                else
                {
                    //MassConfigIPList.Items[0].SubItems.Add("Bad");
                    //continue;


5f56793441655537829519.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2020-09-08
@HemulGM

You cycle through all the lines. You take away the column necessary to you in an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question