killakid24
Tech Stack Builder
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this C# tutorial, I will teach you how to create a program that will get and display the most repeated item in the ListBox.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add one TextBox named TextBox1 that will serve as your input, two buttons named Button1 for adding the inputted text in the ListBox and Button2 for getting and displaying the most repeated text in a ListBox, and one listbox named ListBox1 for displaying the list of inputted text/items in the textbox. You must design your layout like this:
3. For Button1 as adding item to the listbox1. Put this code below.
4. For Button2 as getting and displaying the most repeated item and the number of times it occurs in the listbox, put this code below.
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add one TextBox named TextBox1 that will serve as your input, two buttons named Button1 for adding the inputted text in the ListBox and Button2 for getting and displaying the most repeated text in a ListBox, and one listbox named ListBox1 for displaying the list of inputted text/items in the textbox. You must design your layout like this:

3. For Button1 as adding item to the listbox1. Put this code below.
- public
void
Button1_Click(
System
.
Object
sender, System
.
EventArgs
e)
- {
- // The items inputted in TextBox1 will be added in ListBox1
- ListBox1.
Items
.
Add
(
TextBox1.
Text
)
;
- //Clear the textbox
- TextBox1.
Clear
(
)
;
- }
4. For Button2 as getting and displaying the most repeated item and the number of times it occurs in the listbox, put this code below.
- public
void
Button2_Click(
System
.
Object
sender, System
.
EventArgs
e)
- {
- // initialize global variables
- string
ob1 =
default
(
string
)
;
- string
ob2 =
default
(
string
)
;
- string
ob3 =
default
(
string
)
;
- int
num1 =
default
(
int
)
;
- int
num2 =
default
(
int
)
;
- // create a foreach loop with a parameter of tempLoopVar_ob1 as String as Items of ListBox
- foreach
(
string
tempLoopVar_ob1 in
ListBox1.
Items
)
- {
- // ob1 variable will hold the list of items in ListBox1
- ob1 =
tempLoopVar_ob1;
- // we used again a foreach loop with a parameter of tempLoopVar_ob2 as String as Items of ListBox
- // nested loop
- foreach
(
string
tempLoopVar_ob2 in
ListBox1.
Items
)
- {
- // ob2 variable will hold the list of items in ListBox1
- ob2 =
tempLoopVar_ob2;
- // if the two variables hold the same item in the listbox, it will increment by 1
- if
(
ob1 ==
ob2)
- {
- num1++;
- }
- }
- // if variable num1 will be greater than num2, then num2 will be equal to num1 as ob3 variable will hold ob1
- if
(
num1 >
num2)
- {
- num2 =
num1;
- ob3 =
ob1;
- }
- num1 =
0
;
- }
- // Display the most repeated item in the listbox by variable ob3
- // Display also the number of times it was repeated
- MessageBox.
Show
(
ob3 +
" is repeated "
+
num2.
ToString
(
)
+
" times"
)
;
- }
Output:

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
You must upgrade your account or reply in the thread to view hidden text.