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..
@ 1) I have the scrollbar, I am not sure why you do not see it. If you have a sample application, please attach it to your next post.
@ 2) Using this approach, this would not be possible, because we retemplated the ComboBoxDataItem, and this would be the selected item (a XamDataGrid).
I suggest using the Default styles for the XamComboEditor, that we ship in the DefaultStyles directory in the Infragistics folder on your computer and retemplating the XamComboEditor's template.
Hi Alex. If I can't template the closed drop down to show a specific column then I'll have to take your suggestion and write a template for Combobox. I'm not sure what you mean by use the default style from XamComboEditor? Can you provide a sample? This is what I need to figure out. I guess I should have said in my first post. It doesn't need to be a grid in the combobox it just should "look" like a grid if possible.
Ideally what I would like is a combobox with say 3 columns in each comboboxitem. When I click one "row" it shows perhaps column 2. And when loading when I set the value from say column 1 it selects the correct row. Ideally it would have an aero theme/style to it. Then the last thing would be to somehow create or show a header "row" for each column at the top. I'm guessing that it isn't easy to put in the header column so for that I may need a workaround.
Thanks again for all your help..
So, as I promised.
Having in mind that you want to keep functionality such as theming, styling, I think it is best to stick with the XamDataGrid inside the XamComboEditor. Looking again at the scenario, one grid would suffice - this means one ComboBoxDataItem inside the ComboBoxItemsProvider, which Value would be the DataSource of the XamDataGrid.
The XamComboEditor has one XamDataGrid with several records. The CellClickAction is set to SelectRecord and when a record is selected, SelectedItemChanging event of the grid fires, and we set the Value of the XamComboEditor to this record's cell of choice (in my example index: [0]) and end its edit mode.
We have to use a converter(IValueConverter) for the DisplayText property, because we have retemplated the ComboBoxDataItem and we do not want the whole grid to appear as SelectedItem.
Regarding the headers, I suppose the labels of the grid is what you want to achieve.
I am attaching the sample and please do not hesitate to let me know if you have questions 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,
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 =)
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
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;
}