Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF DataGrid
I have a datagrid with some columns. One of it has a big width. At runtime I see the grid with a scrollbar and I can scroll left an right to see the whole grid.
I like to have that the grid has no scrollbar and each row is wrapped in a new line.
Is this somehow possible?
Posted 26-Feb-13 5:51am
Terkosh584
Comments
Sandeep Mewara at 26-Feb-13 11:20am
   
Have fixed width of the columns as per need to avoid scroll. By default contents should get wrapped, if not, put wrapping for the text.
Sergey Alexandrovich Kryukov at 26-Feb-13 14:24pm
   
Right. Believe or not, I answered the question, please see.
—SA
Sergey Alexandrovich Kryukov at 26-Feb-13 14:17pm
   
Wrapped row? Not wrapped cell content?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I am pretty much sure that none of the grid views can do it: it's beyond the nature of such controls.
 
All you can do is developing of your own custom control, but I don't advices it, it would strongly defeat the purpose of the grid view and would greatly confuse the users, including yourself. Just imagine it's look. It only seems to you that you "like to have". Draw it on paper, screen, or in your imagination, and you will quickly see that you won't like it at all. Better think on the design of narrower grid and perhaps some kind of "drill down", on click, context menu or somehow.
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
You can wrap the text in grid.
 
You have to follow the below steps: 
 
1. GridView width should be in precentage (Width="100%")
2. In the same way you have to give column width (ItemStyle-Width="10%" HeaderStyle-Width="10%")
3. Set ItemStyle-Wrap="true" for wrapping the text
4. Sum of all cilumns width must be equal to 100%
 
Example
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
        GridLines="Vertical" Width="100%">
        <Columns>
            <asp:TemplateField HeaderText="Remarks" ItemStyle-Wrap="true" ItemStyle-Width="80%" HeaderStyle-Width="10%">
                <ItemTemplate>
                    <asp:Label ID="lblRemarks" runat="server" Text='<%# Bind("REMARKS") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Customer" ItemStyle-Width="10%" HeaderStyle-Width="10%">
                <ItemTemplate>
                    <asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CUSTOMERNAME") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Status" ItemStyle-Width="10%" HeaderStyle-Width="6%">
                <ItemTemplate>
                    <asp:Label ID="lblSts" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
 
Regards
Willington
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Thanks for your answers.
The idea with wrapping the text I don't like it because of the row height.
Either I have a fixed row height three times higher than normal to show all contents or
I have auto row height then I have a bumpy view depending if description column is wrapped.
 
This example shows what I like to have:

>>
 Pos   Quantity  Unitprice   Unit  Discount  PO Number Total 
Description
 1 3  5.00 Pc 50% 4512345678   7.50
Chewingum
 2 2 2.00  Pc 10% 4587654321  3.60
Lollypop sweet sour and cherry curry hot style taste
 
I will try to realize it by duplicate each row, make DataGridCells alternating visible or not
and group rows by Pos column.
Any criticism and suggestion are welcome
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100