Click here to Skip to main content
15,921,530 members
Home / Discussions / C#
   

C#

 
QuestionCombo Box SwapItem Pin
PhilDanger12-Jul-07 6:18
PhilDanger12-Jul-07 6:18 
Hi everyone,

I'm trying to write a simple swap function for two items in a combo box (this is used for moving an item in a combo box up or down depending on the button the user clicks).

My problem is that when I set ComboBox.DroppedDown = true, when the user clicks the button again while it is dropped down, (or anywhere else besides the combo box) it switches back to selecting the index that was initially selected. This is a problem when they want to move the same item more than one position -- it doesn't follow the user's selection.
/// <summary>
/// Swaps the names of the frames in the combo box.
/// </summary>
private void SwapFrameNames(int oldIndex, int newIndex)
{
    cmbFrames.DroppedDown = true; //drop the combo box down so the user can see what's going on

    //perform the swap
    object temp = cmbFrames.Items[newIndex];
    cmbFrames.Items[newIndex] = cmbFrames.Items[oldIndex];
    cmbFrames.Items[oldIndex] = temp;

    //select the new position so we follow the user's selection
    cmbFrames.SelectedIndex = newIndex;
}


The code works fine if I comment out the first line of the function -- it follows the selection as expected.

Any ideas?

Thanks,

Phil
AnswerRe: Combo Box SwapItem Pin
Christian Graus12-Jul-07 6:28
protectorChristian Graus12-Jul-07 6:28 
GeneralRe: Combo Box SwapItem Pin
PhilDanger12-Jul-07 7:25
PhilDanger12-Jul-07 7:25 
AnswerRe: Combo Box SwapItem Pin
Luc Pattyn12-Jul-07 7:52
sitebuilderLuc Pattyn12-Jul-07 7:52 
QuestionAjax slowing my search??? Pin
Chris McGlothen12-Jul-07 6:12
Chris McGlothen12-Jul-07 6:12 
AnswerRe: Ajax slowing my search??? Pin
Christian Graus12-Jul-07 6:28
protectorChristian Graus12-Jul-07 6:28 
GeneralRe: Ajax slowing my search??? Pin
Chris McGlothen12-Jul-07 6:36
Chris McGlothen12-Jul-07 6:36 
GeneralRe: Ajax slowing my search??? Pin
Larantz12-Jul-07 12:09
Larantz12-Jul-07 12:09 
GeneralRe: Ajax slowing my search??? Pin
Chris McGlothen12-Jul-07 12:57
Chris McGlothen12-Jul-07 12:57 
GeneralRe: Ajax slowing my search??? Pin
Steve Echols12-Jul-07 15:32
Steve Echols12-Jul-07 15:32 
GeneralRe: Ajax slowing my search??? Pin
Chris McGlothen13-Jul-07 6:04
Chris McGlothen13-Jul-07 6:04 
GeneralRe: Ajax slowing my search??? Pin
Steve Echols13-Jul-07 6:14
Steve Echols13-Jul-07 6:14 
GeneralRe: Ajax slowing my search??? Pin
Larantz13-Jul-07 0:21
Larantz13-Jul-07 0:21 
GeneralRe: Ajax slowing my search??? Pin
Chris McGlothen13-Jul-07 4:34
Chris McGlothen13-Jul-07 4:34 
QuestionHelp with a search & replace Pin
rbuchana12-Jul-07 5:51
rbuchana12-Jul-07 5:51 
AnswerRe: Help with a search & replace Pin
User 665812-Jul-07 6:06
User 665812-Jul-07 6:06 
AnswerRe: Help with a search & replace Pin
Luc Pattyn12-Jul-07 6:12
sitebuilderLuc Pattyn12-Jul-07 6:12 
QuestionProblem Connecting to MQ on unix from .NET application Pin
unnamed00712-Jul-07 4:51
unnamed00712-Jul-07 4:51 
QuestionString containing digit or Alphabet Pin
t4ure4n12-Jul-07 4:33
t4ure4n12-Jul-07 4:33 
AnswerRe: String containing digit or Alphabet Pin
User 665812-Jul-07 4:43
User 665812-Jul-07 4:43 
AnswerRe: String containing digit or Alphabet Pin
Luc Pattyn12-Jul-07 4:45
sitebuilderLuc Pattyn12-Jul-07 4:45 
AnswerRe: String containing digit or Alphabet Pin
Christian Graus12-Jul-07 4:53
protectorChristian Graus12-Jul-07 4:53 
QuestionIOException Problem... Pin
Andy Spier12-Jul-07 4:23
Andy Spier12-Jul-07 4:23 
AnswerRe: IOException Problem... Pin
Luc Pattyn12-Jul-07 4:28
sitebuilderLuc Pattyn12-Jul-07 4:28 
GeneralRe: IOException Problem... Pin
Andy Spier12-Jul-07 4:33
Andy Spier12-Jul-07 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.