How To Load Array Values Into Listbox & ComboBox In C#

combox tutLast 3 days I have been working on a Library Management System, it's for my college actually it's a group project, but i promised my group members that I will code and design the whole system, by the way i really had lots of problems because this would be my first time doing with a database, also I didn't know how a Library Management System works because I have never been to a Library. Hopefully I am almost done, I am going to meet my group members and ask them to make the Documentation.

Loading Array values into a ComboBox, I had to do it in my Library Management System, I will wrote the same code that I used in my Library Management System.

First we need to create a private Const int(const is a special kind of variable....), a private String Array and set value to them.
private const int Total = 13;
        private String[] genre = new String[Total];
Now coming to the function, we'll create a Function called LoadBookGenres(), and set set values to the arrays, adding to the listbox or combobox, by the way you can still go straightly without creating a new Function like you can set the values for the arrays, and load(sort) the array values to the listbox or the combobox in an event(ex:Form_Load).
private void LoadBookGenres()
        {
            //Assign value into Array
            genre[0] = "Adventure";
            genre[1] = "Animals";
            genre[2] = "Computers & Internet";
            genre[3] = "Biography";
            genre[4] = "Comics";
            genre[5] = "Horror";
            genre[6] = "Sports";
            genre[7] = "Romance";
            genre[8] = "Historical";
            genre[9] = "Music";
            genre[10] = "Religion";
            genre[11] = "Mystery";
            genre[12] = "Other";

            //Sort array and fill listbox with the sorted array
            Array.Sort(genre);
            for (int i = 0; i < genre.Length; i++)
            {
                listBox1.Items.Add(genre[i]);
            }
        }
NOTE : Change ListBox1 to your listbox name or your combobox name.
 Remember we set the public const int to 13, always in computer science you should count from 0 and upwards.
Now we just need to call the Function from an event, I called it from Form_load
private void Form1_Load(object sender, EventArgs e)
        {
            LoadBookGenres();
        }

Here is a picture of this in ListBox.
array

Here is a picture of this in ComboBox.
 
I hope this has helped you in someway, Thanks for reading.

How To Add Values To ListBox In C#

Adding values to a listbox is something really easy anyways if you don't know how to add values to a listbox then here you go.

You need to add these things to your project first of all
  1. Three buttons (add,show,clear)
  2. Listbox
  3. Textbox

How To Make A File Searcher And Display Results In A Listbox

Today I will teach you how to display files from your computer in a listbox. The code is very simple and is for beginners so lets get started! First open visual basic 2008 / 2010.
1. Create / open a project.

2. Add a Button and give it the text: "Search".

3. Also add a Textbox and a Listbox.

4. Now double click on the Button and type or copy the following code:
For Each File In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop,
FileIO.SearchOption.SearchAllSubDirectories, Nothing)
              Dim foundFile As String =
              My.Computer.FileSystem.GetFileInfo(File).Name
              If foundFile.Contains(TextBox1.Text) Then
                      ListBox1.Items.Add(foundFile)
              End If
      Next