Datagridview Wrapmode not working

KerrieJMc

New member
Joined
Jul 21, 2014
Messages
2
Location
Ireland
Programming Experience
1-3
Hi,


Im wondering if anyone could help me. I am trying to create a product report which displays all the items sold in a day. The columns will be Barcode, QTY, Product, Price. I use a datagrid with a SELECT query "SELECT Barcode, QTY, Product, Price FROM SalesLog". The fields "run off" the page so I am looking for a way to continue the fields on a new line. I have tried using the wrapmode method but I have had no luck with this so far.




My code is


VB.NET:
   Sub DataGrid_Work()


        'Show in DataGrid.
        'Best method to display table contents in a DataGrid.
        Dim MyTable As New DataTable


        'this displays the current sale from the active table
        CMD.Connection = CN
        CMD.CommandText = "Select Barcode, QTY, Product, Price From SalesLog"
        DataR = CMD.ExecuteReader
        Dim I As Integer
        For I = 0 To MyTable.Rows.Count - 1


        Next
        MyTable.Load(DataR)
        DG1.DataSource = MyTable
        DG1.Refresh()


        'these lines decide what width the columns would be
        Dim columnwidth0 As DataGridViewColumn = DG1.Columns(0)
        columnwidth0.Width = 110


        Dim columnwidth1 As DataGridViewColumn = DG1.Columns(1)
        columnwidth1.Width = 35


        DG1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
        DG1.Columns.Item(1).DefaultCellStyle.WrapMode = DataGridViewTriState.True


        Dim columnwidth2 As DataGridViewColumn = DG1.Columns(2)
        columnwidth2.Width = 150


        DG1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
        DG1.Columns.Item(2).DefaultCellStyle.WrapMode = DataGridViewTriState.True


        Dim columnwidth3 As DataGridViewColumn = DG1.Columns(3)
        columnwidth3.Width = 45


        DG1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
        DG1.Columns.Item(3).DefaultCellStyle.WrapMode = DataGridViewTriState.True
End Sub




Any help is greatly appreciated.


Thanks
Kerrie
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,705
Location
Sydney, Australia
Programming Experience
10+
The WrapMode relates to how the text in a specific cell is wrapped within that cell, not wrapping the cells in a row onto another row. If it's the latter you want then you're out of luck. Can you confirm which it is that you want?

By the way, a DataGridView is a DataGridView, not a DataGrid. A DataGrid is a different control. Please ALWAYS use the correct names for things to avoid confusion.
 
Top Bottom