I am using the xamDataGrid and edit template is assigned to one of the Field of the DataGrid -
xmlns
:infra="http://infragistics.com/Editors"
<Style x:Key="ComboStyle" TargetType="{x:Type infra:ValueEditor}"> <Setter Property ="EditTemplate"> <Setter.Value> <ControlTemplate TargetType="{x:Type infra:ValueEditor}"> <ComboBox Name="uxFacility" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"> </ComboBox> </ControlTemplate> </Setter.Value> </Setter></Style>
This edit template gets assigned to the field at runtime. Now if I use the key board to traverse to the perticular cell (field). as per the template above the combobox gets displayed in the cell but the focus still remains on the cell. I want the focus to get shift to the combox the moment it gets displayed.
any clues?
Thanks in advance.
~Sachin
Hello Sachin,
If you want to retemplate or create a template for your ValueEditors, please take a look at the default generic styles of the XamEditors in the DefaultStyles directory in the Infragistics folder. You can use them as a base for your own style so that you will not lose any important functionality.
You might also find helpful this great article by Andrew Smith about hosting any controls in the XamDataGrid:
http://blogs.infragistics.com/blogs/andrew_smith/archive/2009/03/27/hosting-wpf-controls-in-a-xamdatagrid-cell.aspx
Hope this helps,
Alex.
Hello Alex,
Thanks for your quick response.
I have referred the above mentioned url and the sample. But still i am facing the problem at runtime.
If i apply the EditorStyle at design time it works fine for me but if i apply the same editor style at runtime it does not uses the style and data template does not gets applied.
Am I missing any thing here...
Code which works fine at design time -
<igDP:Field Name="salary"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igSamples:ControlHostEditor}"> <Setter Property="EditDataTemplate"> <Setter.Value> <DataTemplate> <ComboBox /> </DataTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Following is the Code which does not work -
<igDP:XamDataGrid.Resources> <Style x:Key="MultiComboStyle" TargetType="{x:Type igSamples:ControlHostEditor}"> <Setter Property="EditDataTemplate"> <Setter.Value> <DataTemplate> <ComboBox /> </DataTemplate> </Setter.Value> </Setter> </Style></igDP:XamDataGrid.Resources>
the code behind - private void Window_Loaded(object sender, RoutedEventArgs e){ FieldLayout fl = xamDataGrid.FieldLayouts[0]; Field field = fl.Fields["salary"]; field.Settings.EditorStyle = xamDataGrid.FindResource("MultiComboStyle") as Style;}
Please suggest.
Sachin,
Actually I do not see a difference. I added some items to the ComboEditor and when you tab-navigate to the cell, the ComboEditor gets focus and you can use the arrow keys to navigate its items.
What is your requirement and what do you think is not a correct behavior?
Actually the requirement is - As per the sample attached in the previes sample -
Say currently the focus is in the name column. I press the tab key and shift the focus to the salary column. Now I wanted a combo box to appear in the salary cell having the focus inside it.
But when i run the sample and press the tab key a Textbox is getting dispalyed instead of the combobox in the salary column.
Any reason for this. Is it dispalying the combobox in the salary column at your end?
As I can see in your project, you have both references for 8.2 and 9.1.
Here is a screenshot of what I am getting when I run the project and apply the style from the code behind.
Make sure you do not have ambiguous references.
Regards,
Alex,
Thanks for your support.
Now i got the problem. I was assigning the style to the field in the Window_Loaded event. If I assign the style in XamDataGrid_InitializeRecord event it works fine.
Thanks...
Try with FieldLayoutInitialized instead of InitializeRecord.
InitializeRecord would fire each time a record is initialized (when scrolled out-into view,grouped, ungrouped, etc).
In orde for the XamTextEditor to appear again, the Cell must end its edit mode.
To do this, you would have to handle probably selection changed event of the Combo and go up the element tree and find the CellValuePresenter and call the EndEditMode method.
Something like this:
CellValuePresenter cvp = Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(CellValuePresenter), false) as CellValuePresenter;
cvp.EndEditMode(true,true);
Let me know if you have any questions on this.
One more query here.
I have applied a combobox as the EditDataTemplate for the column of the DataGrid. Now i want the combobox to disappear and the selected text should get displayed in the grid cell(field) whenever i select the item from combobox.
Any clues how this can be done.