Showing posts with label ComboBox. Show all posts
Showing posts with label ComboBox. Show all posts

Tuesday, June 26, 2007

ListBox - Select Multiple Items

I've seen quite a number of forums posts asking how to get the selected items of a listbox when the listbox selection mode has been changed to allow for multiple items to be selected. It's actually pretty simple to do in .net.

What you need to do is to loop through the SelectedItems collection to get to the items that have been selected. The list box also has a property called SelectedIndices that you can use.

Download the zip file to see the sample code on this which also shows you how to add a name-value pair item like we used to do in VB6.

Thursday, May 24, 2007

Reading Text File Into Combo Box

In the previous blog (Reading Text File Using StreamReader Class), I demonstrated the use of StreadReader class to read text file. The System.IO.File class also provide us with a couple of ways to read text file as well.

We will use it's capability in this blog to read the data from text file and load it directly into a combo box.

Code sample:

string[] theStates;
theStates=System.IO.File.ReadAllLines(txtFilename.Text);
cboStates.Items.AddRange(theStates);


A sample application is available here.

Load text file into combobox