Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2009, 06:34 AM
Registered User
 
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
 
Old November 16th, 2009, 06:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 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 -/

Think before you post: What have you tried?
 
Old November 16th, 2009, 10:21 AM
Registered User
 
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 :(
 
Old November 16th, 2009, 10:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 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 -/

Think before you post: What have you tried?
 
Old April 6th, 2011, 07:59 AM
Authorized User
 
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

Bind the data to the combo box using a separate private function and call the same in the Form_Load as well on the button_click. If you want to set the selected value at the form_load set the selectedindex=0 and on the button_click loop through the records in the combobox to find the value you want to set the focus with and assign the index of that item to the selectedindex property.
__________________
Thanks in advance.

Regards,

Senthil Kumar M.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.