PC Review


Reply
Thread Tools Rate Thread

Combo Box default value.

 
 
John Denver
Guest
Posts: n/a
 
      20th Apr 2009
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 to get 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 ?



 
Reply With Quote
 
 
 
 
joecool1969@live.com
Guest
Posts: n/a
 
      20th Apr 2009
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.
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      20th Apr 2009
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 ?


somethin like:
string defaultDrive = string.empty;
foreach( ..... in ..GetDriver())
{
string devicestr = ....;
if ( ... is default drive .... )
defaultDrive =devicestr ;
}
if (defaultDrive!=string.empty)
combo.SelectedItem = defaultDrive;

you could do a similar thing with an index:

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default value of combo box based on another combo box Hugh self taught Microsoft Access Form Coding 6 17th Jan 2010 12:16 PM
default value for combo box based on another combo box Jeff @ CI Microsoft Access Form Coding 3 3rd Sep 2008 04:59 AM
Combo Selection on form becomes default value of combo on subform =?Utf-8?B?TmFuY3lNaW1h?= Microsoft Access Form Coding 1 3rd Jul 2005 09:45 PM
"Parent combo" default value does not give me proper rowsource in "child combo" Tom Microsoft Access Form Coding 1 6th Mar 2005 04:22 AM
Default value in combo box = value of another combo box? Geordie Microsoft Access Form Coding 1 16th Mar 2004 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:44 PM.