Project Background
Facts About Project
Question
XAML CODE:
<igCombo:XamWebComboEditor Name="IngredientTypeComboEditor" />
<igGrid:XamWebGrid.Columns>
<igGrid:TextColumn Key="Code" HeaderText="Code" Width="Auto" MinimumWidth="20" />
<igGrid:TextColumn Key="TitleAR" HeaderText="Name Arabic" Width="Auto" MinimumWidth="150" />
<igGrid:TextColumn Key="TitleEN" HeaderText="Name English" Width="Auto" MinimumWidth="150" />
<igGrid:TemplateColumn.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=???, Source={???}}" /> </DataTemplate>
</igGrid:TemplateColumn.ItemTemplate>
<igGrid:TemplateColumn.EditorTemplate>
<ComboBox Name="ComboIngredientType" ItemsSource="{Binding ???}" />
</DataTemplate>
</igGrid:TemplateColumn.EditorTemplate>
</igGrid:TemplateColumn>
</igGrid:XamWebGrid>
VB CODE:
Dim SRV As New DomainService1
Private Sub LoadData()
Me.grdList.ItemsSource = SRV.Ingredients
Me.IngredientTypeComboEditor.ItemsSource = SRV.D_IngredientTypes
Me.IngredientTypeComboEditor.DisplayMemberPath = "TitleEN"
SRV.Load(SRV.GetD_IngredientTypeQuery)
End Sub
Hi,
The DataContext of the DataTemplate properties of a TemplateColumn are the data for the row, in which a cell represents. So, in the ItemTemplate, if you have a property that represents an IngredientType on your Ingredient object, then you would just set that has the Path. And there would be no need to set the Source, as the DataContext would be your source.
As for your ComboBox's ItemSource, you should make a static resource and set that as the ItemsSource for your Combobox, as that would be the simplest approach. If that isn't possible, you can use the CellEnteredEditMode event and and check that your in your TemplateColumn, grab the editor ,cast it as a ComboBox and set the Itemssource.
void DataGrid1_CellEnteredEditMode(object sender, EditingCellEventArgs e)
{
if(e.Cell.Column.Key == "myTempCol")
((ComboBox)e.Editor).ItemsSource = myItemsSource;
}
-SteveZ
Hi
But this event DataGrid1_CellEnteredEditMode does not work for adding new row.
When XAMwebGrid is used for adding a new row , what is the process suggested by Infragistic ?
Shahzad
Hi Shahzad,
The CellEnteredEditMode event fires for each cell in view on the Add New Row.
So the same approach will work.
If use CellEnteredEditModeevent, this event will be triggered by double click on any editable cell like TextBox, but above templateCoulmn not support double click event to enter Edit Mode.
How to resolve this problem?
I'm not sure what you're asking.
All columns thats are editable, support double click editing. (Note you need to make sure that on your Editing settings you have MouseClickAction set to double, however that is the default)
Also, for TemplateColumns and UnboundColumns, they are editiable if and only if you have the EditorTemplate set.
Could you be more specific with your case and the problem you're running into?
Thats b/c you don't have an EditorTemplate defined for your DepartmentID column, so the columns is not editable.
Hi here is my xaml for this case:
<ig:XamGrid ItemsSource="{Binding EmployeeDepartments}" AutoGenerateColumns="false" CellEnteredEditMode="XamGrid_CellEnteredEditMode"><ig:XamGrid.EditingSettings> <ig:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="DoubleClick" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsOnCellActiveEditingEnabled="False" /></ig:XamGrid.EditingSettings><ig:XamGrid.Columns> <ig:TemplateColumn Key="PrimaryInd" > <ig:TemplateColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding ghPrimaryInd, Source={StaticResource localizedStrings}}" HorizontalAlignment="Center" /> </DataTemplate> </ig:TemplateColumn.HeaderTemplate> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <RadioButton IsChecked="{Binding PrimaryInd,Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> <ig:TemplateColumn Key="DepartmentID" > <ig:TemplateColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding ghDepartment, Source={StaticResource localizedStrings}}" HorizontalAlignment="Center" /> </DataTemplate> </ig:TemplateColumn.HeaderTemplate> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <ComboBox x:Name="TheDepartments" DisplayMemberPath="DepartmentName" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> <ig:TextColumn Key="Department.DepartmentName" > <ig:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding ghDepartment, Source={StaticResource localizedStrings}}" HorizontalAlignment="Center" /> </DataTemplate> </ig:TextColumn.HeaderTemplate> </ig:TextColumn> </ig:XamGrid.Columns></ig:XamGrid>
here is the code as you suggested:
private void XamGrid_CellEnteredEditMode(object sender, Infragistics.Controls.Grids.EditingCellEventArgs e) { if (e.Cell.Column.Key == "DepartmentID") { ((ComboBox)e.Editor).ItemsSource = ((MyViewModel)this.DataContext).Departments; } }
When debugging the app, (e.Cell.Column.Key == "DepartmentID") never happened. Double click on the column for combobox, even not trigger above event CellEnteredEditMode.