Hi. In the winforms version of your combobox there is a nice feature to be able to bind a dataset to the combobox to show a grid in the drop down. Is this available in the XamComboEditor. If not any ideas how to set this up?
Hello,
Basically, the XamComboEditor does not support this, but you could retemplate the ComboBoxDataItem's template and put a XamDataGrid inside, so that you can bind to a Collection,DataTable,etc.
<igEditors:XamComboEditor Name="xamComboEditor1">
<igEditors:XamComboEditor.Resources>
<DataTemplate DataType="{x:Type igEditors:ComboBoxDataItem}" >
<Grid>
<igDP:XamDataGrid x:Name="TextBlock" DataSource="{Binding Path=Value}" />
</Grid>
</DataTemplate>
</igEditors:XamComboEditor.Resources>
</igEditors:XamComboEditor>
Then create ComboBoxItemsProvider and add a ComboBoxDataItem, which Value property you can set to a DataTable,Collection,etc. Add the ComboBoxDataItem in the ComboBoxItemsProvider and set the ItemsProvider property of the XamComboEditor.
string[] values = new string[] { "value1", "value2", "value3" };ComboBoxDataItem cb = new ComboBoxDataItem();cb.Value = values;ComboBoxItemsProvider c = new ComboBoxItemsProvider();c.Items.Add(cb); xamComboEditor1.ItemsProvider = c;
Hope this helps.
Hey Alex. This is what I needed, thanks. Question. When I click the drop down it takes a second or two to actually drop down the grid. Does rendering the grid take that long? Do you have that problem? Thanks for your help on this..
Hi Alex. So far this is exactly what I need. I just have a couple more questions.
1. How do I select a value from code. For example. In My ViewModel I have the value I want to select in the dropdown. What's the best way to do this.
2. I don't have a vertical scroll bar. You said you have this? I get a horizontal one but not a vertical one. Do you have any ideas how I can get one to display. I would think I need to wrap the ComboboxItem in a Scrollviewer but now sure.
Thanks again for the help. This functionality is a big requirement for us.
1) I am not sure if that would work in your MVVM scenario, but you have to go down the element tree to the XamDataGrid and select a record ( the same way I used to go up the tree to set the value of the XamComboEditor when a record is selected in the XamDataGrid.
Something like:
XamDataGrid x = Infragistics.Windows.Utilities.GetDescendantFromType(xamComboEditor1, typeof(XamDataGrid), false) as XamDataGrid;
2) I do not believe that the scrollviewer will help much, because the XamDataGrid would not know when it needs to have a scrollbar because it is inside the DropDown of the XamComboEditor. The quickest way around this is to set the Height property of the XamDataGrid which will bring the vertical scrollbar when needed. Is that acceptable if your scenario?
Hi Alex. I think the Height in the Grid will do OK for the scrollbar.
Unfortunately I couldn't get the following line to work. It simply returns null and I don't get a reference to the grid. Does this happen to you?
Thanks again..
I assume you are calling this too early, before the grid is loaded and any records are initialized.
<igDP:XamDataGrid ActiveRecord="{Binding Path=Records[2], RelativeSource={RelativeSource Self}}">
This will get the 3rd record selected automatically.
The other way for this is use the InitializeRecord event and perform some logic there to choose the ActiveRecord:
private void xamDataGrid_InitializeRecord(...)
{
if ((e.Record as DataRecord).Cells["Age"].Value.ToString() == "5")
e.Record.IsActive = true;
}
Hi Alex.
I would like to know, what's wrong with my code. I try to following your code.
on XAML :
<igEditors:XamComboEditor x:Name="comboBox1" KeyboardNavigation.TabIndex="0" > <igEditors:XamComboEditor.Resources> <DataTemplate DataType="{x:Type igEditors:ComboBoxDataItem}" > <Grid> <igDP:XamDataGrid x:Name="DataGrid1" Width="250" Height="250" DataSource="{Binding Path=Value}" HorizontalContentAlignment="Stretch" SelectedItemsChanging="DataGrid1_SelectedItemsChanging"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout > <igDP:FieldLayout.Fields> <igDP:Field Name="Field1" Label="Code"/> <igDP:Field Name="Field2" Label="Field2" Visibility="Hidden"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellClickAction="SelectRecord"/> </igDP:XamDataGrid.FieldSettings> </igDP:XamDataGrid> </Grid> </DataTemplate> </igEditors:XamComboEditor.Resources> </igEditors:XamComboEditor>
at code behind :
private void DataGrid1_SelectedItemsChanging(object sender, Infragistics.Windows.DataPresenter.Events.SelectedItemsChangingEventArgs e) { comboBox1 = Infragistics.Windows.Utilities.GetAncestorFromType(sender as XamDataGrid, typeof(XamComboEditor), false) as XamComboEditor; SelectedRecordCollection record = e.NewSelection.Records; if (record == null || record.Count == 0) return; if ((record[0] as DataRecord).Cells[0].Value == null) { comboBox1.Value = null; } else { comboBox1.Value = (record[0] as DataRecord).Cells[0].Value.ToString(); } comboBox1.EndEditMode(true, true);}
but the value is always null.
could you please give me an advice?
Thanks before.
Vera
Hi,
This post was very useful. I plan to encapsulate this into usercontrol for my project, but encountering below issues. I am using 2010.2 ver.
1) When click on dropdown, previous selected data gets cleared in combo text. How do i retain the previous selected text while dropdown is open?
2) While my dropdown is open, if i did not select any record from grid, after the dropdown is closed, how do i retain previous selected data?
Thanks.
Hi Alex,
Sorry, my bad. I already solved it. =)
Thanks =)