On Apr 20, 2:41*pm, "John Denver" <nos...@spam.com> wrote:
> Hello
>
> On a windows form I've added a combo box, in which I display a list of all
> removable drives and CDRom's *that are attached to my machine. *So toget a
> list of drives I'm using the GetDrives method, and as I loop through that
> collections I look for the correct drive type. *If the type is removable *I
> then make up a string *string devicestr = *Name + VolumeLabel
>
> Once I make up the string I add it to the comboBox
> comboBox1.Items.Add(devicestr);
>
> There may be a more intuitive way of doing that, but my question is this.*I
> always want to default to my CDRom and have that displayed. *How do I make
> my combobox display a certain value ?
You description doesn't indicate it, but I assume when you are looping
through the drive list, you are looking for both Removable and CDROM.
And when you find the CDROM and add it to the ComboBox's Items
collection, save the current index in an int variable. It would be:
this.comboBox1.Items.Count - 1
And after the loading loop set the combobox's SelectedIndex to the int
variable you saved.
|