Dzyann
Dzyann

Reputation: 5218

How to make DataGridColumn ReadOnly but with CaretVisible?

Is there a way to have a DataGrid with a column in ReadOnly mode but with the Caret Visible? Similar to a Textbox when using the IsReadOnlyCaretVisible property? If you set the IsReadOnly property the Column gets disabled and it is not possible to click on the cell.

<DataGrid ItemsSource="{Binding Customers}" AutoGenerateColumns="False">
         <DataGrid.Columns>
             <DataGridTextColumn Binding="{Binding Name}"></DataGridTextColumn>
             <DataGridTextColumn Binding="{Binding Income}" IsReadOnly="True"></DataGridTextColumn>
         </DataGrid.Columns>
</DataGrid>

Upvotes: 1

Views: 1028

Answers (1)

Ayyappan Subramanian
Ayyappan Subramanian

Reputation: 5366

You can create a DataGridTemplateColumn with TextBox. refer below code.

<DataGridTemplateColumn Header="Name">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox Text="{Binding Name}" IsReadOnly="True" IsReadOnlyCaretVisible="True"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>                   
            </DataGridTemplateColumn>

Upvotes: 1

Related Questions