Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I have a Datagrid with binding the itemssource as Datatable. The table results dynamically binding in the grid. So I haven't specify any columns in Xaml.

I have provided add, edit, delete option in the grid. The problem is I cannot add the multiline text in datagrid text box column. It accepts only the first row of the content.

What I have tried:

Here is my Xaml Code :

C#
<pre><DataGrid
                        x:Name="autoBook_Datagrid"
                        HorizontalScrollBarVisibility="Auto"
                        VerticalScrollBarVisibility="Auto"
                        ScrollViewer.CanContentScroll="True"
                        BorderBrush="{StaticResource GreenBrush}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        RowHeight="25"
                        GridLinesVisibility="All"
                        ClipboardCopyMode="IncludeHeader"
                        ItemsSource="{Binding DynamicBindingTable, UpdateSourceTrigger=PropertyChanged}"
                        CanUserAddRows="{Binding CanAddNewRows, UpdateSourceTrigger=PropertyChanged}"
                        VirtualizingPanel.VirtualizationMode="Recycling"
                        VirtualizingPanel.ScrollUnit="Pixel"
                        EnableColumnVirtualization="True"
                        EnableRowVirtualization="True"
                        FocusVisualStyle="{StaticResource ButtonFocusVisual}"
                            CanUserDeleteRows="False"
                        >



Normally we can set acceptsreturs property in textbox to update the multiline text. But here I don't know what to do in this case.

Could you please help me on this issue to update the multiline text in the datagrid text.

Regards,
Arunkumar Murugesan
Posted
Updated 14-Apr-20 19:35pm

1 solution

Check this: wpfdatagrid - WPF DataGridTextColumn multi-line input - Stack Overflow[^]

XML
<DataGridTextColumn Header="Message" Binding="{Binding Path=Message}"  Width="Auto">
        <DataGridTextColumn.ElementStyle>
            <Style TargetType="TextBlock">
                <Setter Property="TextWrapping" Value="Wrap" />
            </Style>
        </DataGridTextColumn.ElementStyle>
        <DataGridTextColumn.EditingElementStyle>
            <Style TargetType="TextBox">
                <Setter Property="TextWrapping" Value="Wrap" />
                <Setter Property="AcceptsReturn" Value="true" />
            </Style>
        </DataGridTextColumn.EditingElementStyle>
    </DataGridTextColumn>
 
Share this answer
 
Comments
Arunkumar Murugesan 15-Apr-20 2:24am    
Hi Maciej,

Thanks for your update. In your solution we know the column name and we can easily set the style. But in my case, I will load multiple table values into the grid. So I haven't mention any column name in xaml. I have binding the Datatable values directly into the Grid. Its a dynamic one.

For this case, How could I resolve this?
Maciej Los 15-Apr-20 2:36am    
Arunkumar Murugesan 15-Apr-20 3:06am    
Yes Maciej. I agree with it. But Here I have nearly 200 tables and I can get the result of each table from SQL and directly binding into the grid without preparing any columns. In this case we cannot use the multiple view right?

So in this case I just need to accepts the multiline text whenever the datagrid column getting edited.
Maciej Los 15-Apr-20 3:52am    
I don't get you... Do you want to edit table data directly in WPF form? In WPF you are using MVVM pattern (Model-View -ViewModel) to "serve" data to the client. So, if your application does NOT implement MVVM patten, it makes no sense... Sorry.
Arunkumar Murugesan 15-Apr-20 4:22am    
Actually what I have done so far is,

1. I have listed the tables in combobox. We will get the result from the SQL based the tables chosen. Each table having minimum 20 columns.
2. In this case, I have directly binding the Datatable into the Datagrid. All these I have implemented with MVVM pattern only
3. Also I have provided option in editing the cell values. We can double click the cell to paste the values to update.
4. For this case, I tried to paste the content in the grid cell like the mail body content. From this content, first row of the value only pasted in the grid cell. All the content will be pasted in grid cell. This is my issue actually.

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



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