Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Simple combobox question: C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 12 Dec 2004 17:11 GMT
I have a combobox on a WinForm.

I can assign an entire array to the Items collection and have it display in
the drop down list.

But how to I make a particular item the selected item (i.e., the one that is
displayed in the combobox on Form.Load)?

I can hard code a value with
   comboBox1.Text="X";

But I want to do somthing like:
   comboBox1.SelectedItem=1;

Where 1 is the position in the array of the selected item.
Herfried K. Wagner [MVP] - 12 Dec 2004 17:13 GMT
"Dave" <davefrick@newsgroup.nospam> schrieb:
> But how to I make a particular item the selected item (i.e., the one that
> is displayed in the combobox on Form.Load)?
[quoted text clipped - 6 lines]
>
> Where 1 is the position in the array of the selected item.

\\\
With Me.ListBox1
   .Items.AddRange(New String() {"Item1", "Item2", "Item3"})
   .SelectedIndex = 2
End With
///

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Peter Jausovec - 12 Dec 2004 19:57 GMT
or in C# :) :

listBox1.Items.AddRange (new string [] {"Item1", "Item2", "Item3"});
listBox1.SelectedIndex = 2;

Signature

Regards,
Peter Jausovec
(http://blog.jausovec.net)

> "Dave" <davefrick@newsgroup.nospam> schrieb:
>> But how to I make a particular item the selected item (i.e., the one that
[quoted text clipped - 14 lines]
> End With
> ///
Herfried K. Wagner [MVP] - 12 Dec 2004 20:28 GMT
"Peter Jausovec" <peter@jausovec.net> schrieb:
> or in C# :) :

Ooops.  I missed that ;-)...

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.