I have this combox field in my xamdatagrid how can I change the selectedIndex by code I c#
<igWPF:ComboBoxField Name="fejl" Label="Fejl" DisplayMemberPath="FejlTekst" ValuePath="FejlTekst" BindingType="Unbound" Visibility="Collapsed">
<igWPF:ComboBoxField.Settings> <igWPF:FieldSettings> <igWPF:FieldSettings.EditorStyle> <Style TargetType="{x:Type igWPF:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding DataItem.fejl}"/> <Setter Property="DisplayMemberPath" Value="FejlTekst"/> <Setter Property="SelectedIndex" Value="0"/> <Setter Property="ValuePath" Value="{Binding DataItem.fejl}"/>
</Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:ComboBoxField.Settings> </igWPF:ComboBoxField>
var curXCE = curCVP.Editor as Infragistics.Controls.Editors.XamComboEditor;
Hi Bozhidara
I tried to implement your example in my code inside the foreach loop where I loop over datarecords in the xamdatagrid and it was in visual studio where it came with the cast exception
System.Console.WriteLine(curCVP.Editor.GetType()); XamComboEditor curXCE = curCVP.Editor as XamComboEditor;
When I try your example I get an cannot cast error
XamComboEditor curXCE = curCVP.Editor as XamCombo
Hello Thomas,
Thank you for reaching out.
You could programmatically set the selected index of a XamComboEditor with the help of its SelectedIndex property, or alternatively set a SelectedItem.
Since your combo is an editor of a field in a XamDataGrid, you can access it from a cell’s CellValuePresenter, which exposes an Editor property. Additionally, based on this forum thread created by you recently, I extended the sample there to programmatically set the selected indexes for each record:
int cnt = 9; foreach (Record rec in this.xdg.Records) { CellValuePresenter curCVP = CellValuePresenter.FromCell((rec as DataRecord).Cells["Label"]); XamComboEditor curXCE = curCVP.Editor as XamComboEditor; curXCE.SelectedIndex = cnt--; // or //curXCE.SelectedItem = (curXCE.ItemsSource as List<string>)[cnt--]; }
Best regards,Bozhidara PachilovaAssociate Software Developer
8547.XDGComboFieldDemo.zip