p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Go Back   p2p.wrox.com Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2009, 06:34 AM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to refire selectedindex event of combobox in c#

Hello all
i am developing a window application using vs2008

at this moment i want to re-fire selected index event of a combo box upon hitting a button.

the combo box belongs to dropdownlist type.

what is appropriate way to do this ?

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 16th, 2009, 06:39 AM
samjudson's Avatar
Friend of Wrox
Points: 4,955, Level: 29
Points: 4,955, Level: 29 Points: 4,955, Level: 29 Points: 4,955, Level: 29
Activity: 82%
Activity: 82% Activity: 82% Activity: 82%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,453
Thanks: 0
Thanked 50 Times in 50 Posts
Default

The easiest way is to simply refactor your code so the OnSelectedIndexChanged event calls a method, and then call the method in the Button OnClick event as well.

Alternatively you can call an event method exactly like any other method:

Code:
   Combo1_SelectedIndexChanged(null, EventArgs.Empty);
__________________
/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 16th, 2009, 10:21 AM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmm thanks for your reply but this is not what i was looking for.

in fact, upon hitting a button i want to reload combo box as it was on form load & as i had said earlier this belongs to drop down list (not drop down) so i couldn't apply combo1.text="";

i want to set combo to its default selected item (that is blue bar).

i am sorry if i gave wrong information earlier :(
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 16th, 2009, 10:29 AM
samjudson's Avatar
Friend of Wrox
Points: 4,955, Level: 29
Points: 4,955, Level: 29 Points: 4,955, Level: 29 Points: 4,955, Level: 29
Activity: 82%
Activity: 82% Activity: 82% Activity: 82%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,453
Thanks: 0
Thanked 50 Times in 50 Posts
Default

Well a DropDownList must always have an item selected, so you just need to set the SelectedIndex to whichever item is the 'default' - e.g. the first one:

DropdownList1.SelectedIndex = 0;
__________________
/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectedIndex in datalist dhoward VB.NET 2002/2003 Basics 0 August 28th, 2008 11:15 AM
Change of event using 2 combobox yogeshyl Excel VBA 0 July 31st, 2007 06:02 AM
Combobox SelectedIndex Issue kancha C# 7 July 26th, 2006 08:14 AM
comboBox selectedindex problem ColdFusion C# 4 May 12th, 2006 06:37 AM
Combobox SelectedValueChanged Event Frankvk Pro VB.NET 2002/2003 2 March 12th, 2005 07:28 PM



All times are GMT -4. The time now is 11:48 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc