About listbox show the result.

MiPakTeh 1,476 Reputation points
2022-07-09T08:22:25.337+00:00

Hi All,

After find the Max and Min in Listbox look like ;

Min = 3 Min Item = 2.
Max = 17 Min Item = 7

I want change to listbox3 as bellow;

Min = 3 Min Item = 2, Max = 17 Min Item = 7.

Use this code how to do?.

text file;
2484,7381,3099,6847,7716,7303,1255,1098,0070,6770,3116,4772,4180,3007,7765,9934,3577,9958,6646,3794,0548,0473,1359
1586,0764,1270,3897,9473,5890,5301,0690,6699,0192,5633,5749,1199,1179,5263,4982,0632,3631,3582,9476,4383,4435,1196
5561,6611,5226,9148,3861,8905,9496,4827,8155,2949,6070,4258,4127,5420,7665,0103,6351,9750,8568,0718,8321,2550,4521
2929,7321,4246,4751,5353,2879,8051,3660,9318,9314,3877,3808,9373,5963,7799,8519,8047,4656,2443,7175,8197,1135,6956
4873,1140,0526,8629,1957,0320,1808,9744,2638,3422,5194,3896,9702,3897,8481,4789,6565,9749,6542,6852,2025,8094,1484
9147,0705,3483,3879,8400,8082,1896,1070,2702,8110,7395,1644,6930,4872,6207,4240,5318,7348,8822,7593,6432,1271,4657

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.IO;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
  
namespace SATU_1  
{  
    public partial class Form1 : Form  
    {  
        List<string> Data1 = new List<string>();  
        List<string> Data2 = new List<string>();  
  
        List<ItemInfo> Items = new List<ItemInfo>();  
  
        public Form1()  
        {  
            InitializeComponent();  
        }  
  
        private void Form1_Load(object sender, EventArgs e)  
        {  
            //foreach (var s in File.ReadLines(@"C:\Users\family\Documents\Tool_Ori.txt").Skip(4980).Select(s => s.Split(new[] { ',' }, 3)[2]))  
            foreach (var s in File.ReadLines(@"C:\Users\family\Documents\Tool.txt"))  
                {  
                Data1.Add(s);  
            }  
            foreach (var item in Data1)  
            {  
                listBox1.Items.Add(item);  
            }  
        }  
  
        private void button1_Click(object sender, EventArgs e)  
        {  
  
  
            foreach (var item in Data1)  
            {  
                listBox2.Items.Add(item);  
  
                var MyItems = new List<myItem>();  
  
                int min = int.MaxValue;  
                int max = int.MinValue;  
  
                for (int j = 0; j <= 9; j++)  
                {  
                    String Number_ = j.ToString();  
                    int NumberCount_ = item.Replace(",", "").ToCharArray().Count(c => c.ToString() == Number_);  
  
                    MyItems.Add(new myItem() { Index = Convert.ToInt32(Number_.ToString()), Value = NumberCount_ });  
  
                }  
                foreach (myItem ITM in MyItems)  
                {  
                    listBox2.Items.Add(ITM);  
                }  
  
                foreach (myItem ITM in MyItems)  
                {  
                    if (ITM.Value < min)  
                    {  
                        min = ITM.Value;  
                    }  
  
                    if (ITM.Value > max)  
                    {  
                        max = ITM.Value;  
                    }  
                }  
  
                foreach (myItem ITM in MyItems)  
                {  
                    if (ITM.Value == min)  
                    {  
                        listBox2.Items.Add("Min = " + min.ToString() + "  " + "Min Item = " + ITM.Index.ToString());  
                        Items.Add(new ItemInfo() { A_ = min.ToString(), B_ = ITM.Index.ToString() });  
                    }  
                    if (ITM.Value == max)  
                    {  
                        listBox2.Items.Add("Max = " + max.ToString() + "  " + "Max Item = " + ITM.Index.ToString());  
                        Items.Add(new ItemInfo() { C_ = max.ToString(), D_ = ITM.Index.ToString() });  
                    }  
  
                }  
            }  
        }  
  
        private void button2_Click(object sender, EventArgs e)  
        {  
            foreach (ItemInfo ITM in Items)  
            {  
                string resultstr = string.Format("Max Numbers ={2}({3}) Min Numbers ={0}({1})", ITM.A_, ITM.B_, ITM.C_, ITM.D_);  
                listBox3.Items.Add(resultstr);  
            }  
  
        }  
  
        private void button3_Click(object sender, EventArgs e)  
        {  
  
        }  
    }  
}  
public partial class myItem  
{  
    public int Index;  
    public int Value;  
  
    public override string ToString()  
    {  
        return Index.ToString() + " => " + Value.ToString();  
    }  
}  
  
public partial class ItemInfo  
{  
    public string A_ { get; set; }  
    public string B_ { get; set; }  
    public string C_ { get; set; }  
    public string D_ { get; set; }  
  
    public override string ToString()  
    {  
        return A_ +  B_ +  C_ + D_;  
    }  
}  
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,287 questions
{count} votes

Accepted answer
  1. Jack J Jun 24,641 Reputation points Microsoft Vendor
    2022-07-11T02:56:46.823+00:00

    @MiPakTeh , Welcome to Microsoft Q&A, you could try the following code to show the result as you wanted.

    219306-image.png

    code.txt

    Note: I can not give the code in my answer, so I used image to replace it.

    Result:
    219325-image.png


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.