Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem with custom ComboBox & CurrencyManager
 

Problem with custom ComboBox & CurrencyManager

I have a control that inherits from ComboBox. In some of my code I want to un-select what is currently selected in the combo. I do think by setting SelectedIndex = -1. This works fine, except sometimes it will suddently selected the first item in the list. It appears to be coming from the CurrencyManager.OnPositionChanged event (not my code). Any ideas? Here is the stack trac:

System.Windows.Forms.dll!System.Windows.Forms.ComboBox.SelectedIndex.set(int value) + 0xa3 bytes
System.Windows.Forms.dll!System.Windows.Forms.ListControl.DataManager_PositionChanged(object sender, System.EventArgs e) + 0x2e bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChanged(System.EventArgs e) + 0x39 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordState(int newPosition, bool validating, bool endCurrentEdit, bool firePositionChange, bool pullData) + 0x14f bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.Position.set(int value) + 0x40 bytes
System.Windows.Forms.dll!System.Windows.Forms.ComboBox.OnSelectedIndexChanged(System.EventArgs e) + 0xed bytes
Wil Burton  Wednesday, August 19, 2009 3:49 PM

Hi,

->except sometimes it will suddently selected the first item in the list.

When does it suddenly change the selected index? If the datasource is reset, the selectedIndex will be set to 0.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, August 26, 2009 10:20 AM
It seems to happen when I set the SelectedIndex to -1, I have gotten around this by setting it twice, because the first time it doesn't really work, I end up at SelectedIndex 0.
Wil Burton  Wednesday, August 26, 2009 7:43 PM
Wil,

I just thought I'd validate your workaround ... I have usedthis workaround (setting SelectedIndex = -1 twice) since the old 1.1 daysback in 2002. It seems to solve the problem, so what the heck. ;0)
~~Bonnie Berent [C# MVP]
BonnieB  Thursday, August 27, 2009 4:26 AM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Best regards,
Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, August 30, 2009 1:30 PM

You can use google to search for other answers

Custom Search

More Threads

• Trouble with xsd
• How to apply ColumnStyle and Alternating Row style
• Change connection on TableAdapter in code?
• .GetChanges Code is Detecting Changes Where There Are None
• combobox and height
• How to get the databound combobox selected text in the datagrid
• multiple bindingsource filters
• Binding.Format not firing when filtering BindingSource yields no records ???
• BindingSource List property doesn't return records from bound relationship or filter
• DataGridViewComboBoxColumn setting default value from another table than DataSource