Click here to Skip to main content
14,732,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am working on WPF application,Here i am trying to change the value based on combobox selection in datagrid.But if i click on cell(double click or single click) i am not getting the combobox.
I am using the below code.
<DataGrid Grid.Row="1" Grid.Column="3" x:Name="fieldGrid" 
   AutoGenerateColumns="False" GridLinesVisibility="None"  AllowDrop="True" Drop="__fieldGrid_Drop" PreviewDrop="__fieldGrid_PreviewDrop">
 <DataGrid.Columns >
<DataGridTemplateColumn Header="Source Table Columns"  Width="*" 
 CanUserResize="True" IsReadOnly="True" CanUserSort="True" SortMemberPath="ColumnName"
 CellTemplate="{StaticResource DataSourceCellTemplate2}" CellEditingTemplate="{StaticResource EditingDateTemplate}" SortDirection="Ascending"/>
</DataGrid.Column>
 </DataGrid>

and i created CellTemplate and CellEditingTemplate seperately.that code is below.
<datatemplate x:key="DataSourceCellTemplate2">
<stackpanel orientation="Horizontal" margin="1,3">
<textblock name="dsFieldText2" text="{Binding Value}">



<datatemplate x:key="EditingDateTemplate">
<stackpanel orientation="Horizontal" margin="1,3">
<combobox>



If i click on cell even i am not getting empty combobox.
Anyone could you please help me.

What I have tried:

I have been tried so many articles.I have used the below code
<DataGridTemplateColumn Header="">
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox IsEditable="False" 
                Text="{Binding ComponentIdentifier,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                ItemsSource="{Binding Path=ApplicableIdentifiers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ComponentIdentifier}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>


If i used this code the i am getting this error edititem is not allowed for this view in wpf datagrid
Posted
Updated 25-Aug-19 12:33pm
v2

1 solution

<DataGridTemplateColumn Header="Source Table Columns"  Width="*" 

 CanUserResize="True" IsReadOnly="True" CanUserSort="True"

 SortMemberPath="ColumnName"
 CellTemplate="{StaticResource DataSourceCellTemplate2}" CellEditingTemplate="{StaticResource EditingDateTemplate}" SortDirection="Ascending"/>
   
Comments
Ram349 26-Aug-19 5:07am
   
Hi Gerry,Thanks for responding my post.I have tried IsReadOnly="True",But still i am getting same issue.Could you please suggest any alternative solution.
Richard Deeming 27-Aug-19 14:40pm
   
What Gerry was saying is that you've already set IsReadOnly="True", which means that the column is read-only. You cannot edit a read-only column.

Either change it to IsReadOnly="False", or remove the IsReadOnly attribute.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900