Wednesday, June 24, 2009

Infragistics XamComboEditor SelectedIndex -1 doesn't work!

I was trying to use the Infragistics WPF controls and got stuck in the XamComboEditor. I was setting its ItemsSource to a list of ComboBoxDataItem objects and I wanted to have none of them selected by default. I had tried SelectedIndex -1, SelectedItem {x:Null}, Value {x:Null} to no avail. By some ridiculous functionality, the XamComboEditor would select some item in the middle of the list.

Then, in a flash of luck, I got it right. Value="". That was it! Even if IsEditable was false and the documentation mentioned Value could not be changed if IsEditable is false. Of course, they probably meant the user cannot change the Value not me, the developer, but still. Also, setting the Value to null did not work. Once in a lifetime I am not lazy and use {x:Null} instead of a simple empty string and it backfires. Sheesh!


Anushree Phansalkar said...


I am facing the exact issue you've blog-ed here. And I tried to follow your suggestion but with n luck!

Here's what I'm trying to work with:

igWPF:ComboBoxItemsProvider x:Key="MarketsProvider" ItemsSource="{Binding Markets, Source={StaticResource AllComboBoxItemSource}}" DisplayMemberPath="CountryName" ValuePath="CountryCode"

Style x:Key="MarketsDropdownStyle" TargetType="{x:Type igWPF:XamComboEditor}" BasedOn="{StaticResource DefaultXamComboEditorStyle}"
Setter Property="ItemsProvider" Value="{StaticResource MarketsProvider}"
Setter Property="Value" Value=""
!--<Setter Property="DisplayMemberPath" Value="CountryName"
Setter Property="ValuePath" Value="CountryCode"

and this dropdown style is applied to the editable-dropdown of one of the datagrid columns.

As you can see from the commented code, I've tried all permutations possible but alas!

If I use ItemsProvider, DisplayMemberPath, ValuePath and Value="" in my DropDownStyle, the random selected value in the dropdown does go away but the values in the dropdown are not populated correctly!

Working around this for ages now, just came across your blog today and keeping my fingers crossed that you'd be able to help me!


Siderite said...

Well, the bad news is that I haven't worked in the field of WPF for a long time and I certainly wouldn't start again by using Xam controls.

I am sure it worked then, though, so it is either about some thing you did not do and I did, like specifying IsEditable false or something like that, or they "fixed" the bug and you are out of luck and must do it some other way.

If you think about it, it is a sort of a bug. If you have an HTML select with values, one of them is always selected. The way to not select any is to use an empty option item and some validation. Maybe you can use this method.

Another solution (although it sounds like an ugly hack to me) is to set IsEditable true, set the value to nothing, but set IsEditable to false when focused. I have no idea what the control would do in this case.