Vibrant discussion about CSLA .NET and using the framework to build great business applications.
SelectedValue worked in .NET 3.5, but broke when I upgraded to .NET 4. Your class fixes the problem very nicely. Thanks so much for posting it!
Jaans: Ps: Hannes, lyk my die boere moet mekaar maar help.
Ps: Hannes, lyk my die boere moet mekaar maar help.
You got me there. At first I thought it was dutch but of course it's afrikaans
Tiago Freitas Leal, CslaGenFork (Open Source CSLA code generator)
Hi Jaans,
I'd lik to add the ComboBoxEx class/control to CslaContrib.Xaml.Silverlight project to make it more easily available for Csla developers.
Would you agree to submit the extended control to cslaContrib?
Jonny Bekkum, Norway CslaContrib Coordinator
Hi Jonny
Sure! No problem... let me know if I can help.
Happy 2011 !!
Hi all
If you would like to help put pressure on Microsoft to fix the ComboBox for Silverlight, please cast you votes here at user voice:
http://dotnet.uservoice.com/forums/4325/suggestions/1273023
Jaans
I am using your cutom combobox and I got this error message
Cannot call StartAt when content generation is in progress.
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem) at System.Windows.Controls.ComboBox.SetContentPresenter(Int32 index) at System.Windows.Controls.ComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item) at Smac.Controls.CustomComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item)
I have trying to find out what's going on, but I am stuck. Do have any idea about this error message?
Thanks, Kita
Hi Kita
Unfortunately I haven't seen that particular error message before.
From the error stack it would appear that the PrepareContainerForItemOverride is being called at an inappropriate time. The ComboBox solution at the start of this thread does not override it, so I'm assuming your code does directly (or indirectly) - likely ways that could cause it are:
Check your code and comment out any method overloads for the combobox, styles (explicit or implicit), maybe even temporarily disable themes (if you're using them) just to figure out what the source this error is.
Hope that helps some,Jaans
hallo, thanks for that implementation.
your combobox works great with selectedvalue but in my case i have two comboboxes. the first is the "master" combobox, the second the "slave" combobox. the slave combobox should populated (itemsource property) dependend on the selected item of master combobox. some master items has no sub items.
when i select one master item which should not has sub items the itemsource of slave combobox is updated, the converter is getting the selected item of master combobox and returning a collection with zero items. but the combobox is not updating correctly, i can see that the slave combox.itemsource.count is zero but the old selected item is shown ! also the selected index is wrong index...
any idea how i can fix it?
best regards
i have solved the problem by looking on your old post about the combobox :)
i have changed the code:
/// <summary> /// Sets the selected value suppressing change event processing. /// </summary> /// <param name="newSelectedValue">The new selected value.</param> private void SetSelectedValueSuppressingChangeEventProcessing(object newSelectedValue) { try { _suppressSelectionChangedUpdatesRebind = true; SelectedValue = newSelectedValue; var sel = (from item in this.Items where GetMemberValue(item).Equals(newSelectedValue) select item).SingleOrDefault(); this.SelectedItem = sel; } finally { _suppressSelectionChangedUpdatesRebind = false; } }
know it works fine...
here my xaml code:
<myctrl:ComboBoxEx x:Name="cmboxSubType" DisplayMemberPath="DisplayMember" SelectedValuePath="ValueMember" SelectedValueProper="{Binding Path=SubType, Mode=TwoWay}" ItemsSource="{Binding ElementName=cmboxType, Path=SelectedItem, Converter={StaticResource EnumToComboBoxItemsConverter}, ConverterParameter=SUBTYPE}" > </myctrl:ComboBoxEx>
You just saved me a lot of time. This bug is so annoying. Your fix worked like a charm.
Thanks!!
Hi there Jaans,
Wow, okay I'm a bit of a newbie, but your code has saved me a lot of arsing around. All I wanted to do was to be able to update the text that we can see when the combo box is not in drop down mode. Jesus H Christ was that like trying to pull teeth. I was on the Silverlight forums for days... but this fixes it.
I created an account just so I could tell you how grateful I am for this.
In my project I replaced the original combobox with the extended one and now binding to nullable foreign keys became easy. But I noticed that if ItemsSource of the combo is bound to ICollectionView, CurrentChanged event of the view doesn't get fired...
To handle this situation I modified the ComboBoxEx_SelectionChanged event handler:
private void ComboBoxEx_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Avoid recursive stack overflow if (_suppressSelectionChangedUpdatesRebind) return; if (e.AddedItems != null && e.AddedItems.Count > 0) { //SelectedValueProper = GetMemberValue( e.AddedItems[0] ); SelectedValueProper = SelectedValue; // This is faster than GetMemberValue if (this.ItemsSource is ICollectionView) (this.ItemsSource as ICollectionView).MoveCurrentTo(this.SelectedItem); } // Do not apply the value if no items are selected (ie. the else) // because that just passes on the null-value bug from the combobox }
I wanted to provide an update on something I found related to Jaans' fix. While using his solution, I came across an issue in SL4/CSLA 4.1 where I would select a combobox item from the list but the item would not appear as the selected item. If I selected the same item a second time, it finally appeared as selected. In addition, binding was not working...it wouldn't save.
I tried Walk's modification, and it seemed to make the selection issue work correctly (i.e. the first selection made the item actually appear as selected), but two-way binding was still not working. I noticed the other combobox on my usercontrol was working fine with Jaans' code, so I began to look at what was different between the two. Turns out the problem had something to do with binding to a managed property that was defined as a byte. I changed this to an int and everything started working fine.
Tim
I can use this getting selected value is working fine but i need selectionChanged for my own use. i hae functionalities using selectionchanged in my project. And also when i use this im receiving an error
"Failed to assign to property 'System.Windows.FrameworkElement.Style'. [Line: 279 Position: 240]"
can u help me out...
A quick solution is, store the selected item in a tempure var, then restore the item from it.