Hi,
I have a XamGrid which has a template column of type Combo Box. The issue is if I select any value on the cell (Combo box value) and right click on it, the context menu opens up which has cut, copy , paste and in which only paste is enabled and cut, copy are disabled. I want to disable this feature i dont want this context menu opening up when I right click on any value in any cell. I have attached the screenshot of the issue.
Thanks
Arpita
Hello Arpita,
You should handle the GotFocus event of the ComboBox from the ComboBoxTemplate and put the code I shared with you inside its handler.
Hope this helps you.
I actually didn't understand this one.
I have a combo box template defined inside my XamGrid. I already have some events defined for XamGRid. This is my XamGrid definition.
<ig:XamGrid x:Name="UpdateParameterGrid" Grid.Row="0" MinWidth="600" AutoGenerateColumns="False" Width="Auto" ItemsSource="{Binding AffectedRecipes, Mode=TwoWay}" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Center" MaxWidth="1055" HorizontalContentAlignment="Center" FontFamily="Tahoma" FontSize="12" BorderBrush="DarkGray" BorderThickness="0.8" CellControlAttached="UpdateParameterGrid_CellControlAttached" CellEnteringEditMode="UpdateParameterGrid_CellEnteringEditMode" CellExitingEditMode="UpdateParameterGrid_CellExitingEditMode" ><!--CellEnteringEditMode="UpdateParameterGrid_CellEnteringEditMode" CellExitedEditMode="UpdateParameterGrid_CellExitedEditMode" CellExitingEditMode="UpdateParameterGrid_CellExitingEditMode" >--><ig:XamGrid.CellStyle><Style TargetType="ig:CellControl"><Setter Property="BorderThickness" Value="0,0,1,1" /></Style></ig:XamGrid.CellStyle><ig:XamGrid.GroupBySettings><ig:GroupBySettings AllowGroupByArea="Hidden" GroupByOperation="MergeCells" /></ig:XamGrid.GroupBySettings><ig:XamGrid.Columns><ig:TextColumn Key="Sel_Crit_Inst_Name" HeaderText="Instances" TextWrapping="Wrap" IsReadOnly="True" MinimumWidth="100" /><ig:TextColumn Key="Sel_Crit_Inst_Id" Visibility="Collapsed" /><ig:TextColumn Key="Recipe" HeaderText="Recipe" IsReadOnly="True" TextWrapping="Wrap" MinimumWidth="200" /><ig:TextColumn Key="RecipeKey" Visibility="Collapsed" /><ig:TextColumn Key="OldParameterValue" HeaderText="Old Value" TextWrapping="Wrap" IsReadOnly="True" MinimumWidth="200"/><ig:TextColumn Key="OldParamVersion" Visibility="Collapsed" /><ig:TemplateColumn EditorTemplate="{StaticResource ComboBoxTemplate}" ItemTemplate="{StaticResource ComboBoxTemplate}" HorizontalContentAlignment="Stretch" Key="NewParameterValue" IsReadOnly="False"/><ig:TextColumn Key="NewParamVersion" Visibility="Collapsed" /><ig:CheckBoxColumn Key="IsPCGAccesible" Visibility="Collapsed" /></ig:XamGrid.Columns><ig:XamGrid.EditingSettings><ig:EditingSettings AllowEditing="Hover" /><!--<ig:EditingSettings AllowEditing="Cell" IsOnCellActiveEditingEnabled="True" IsMouseActionEditingEnabled="SingleClick" />--></ig:XamGrid.EditingSettings></ig:XamGrid>
How can I actually achieve this here? Can you please help how this can be done with my current XamGrid setting.
I have been looking into the default Style of the MS ComboBox and since there the Style of the TextBox is set to null it means that a Style is applied by code and this is why the Style I suggested you doesn't apply. I can suggest you handle the ComboBox's GotFocus event and add the following code in its handler:
TextBox tb = Utilities.GetDescendantFromName(sender as DependencyObject, "PART_EditableTextBox") as TextBox; tb.ContextMenu = null;
I tried your solution but it didn't solve the issue. I included this in my XamGrid Resources section.
<ig:XamGrid.Resources> <Style TargetType="{x:Type TextBox}"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu Visibility="Collapsed"/> </Setter.Value> </Setter> </Style> </ig:XamGrid.Resources>
I appologize I haven't been clear enough. Since the ComboBox has a TextBox inside its Template, you should create a Style for the Textbox, because the ContextMenu is se t there by default.
Please let me know if this helps you or you need further assistance on this matter.