none
DataGridView multicolumn wordwrap method - is there a setting or property for this? RRS feed

  • Question

  • I have a multicolumn DataGridView and only one column, the last column, will have more than a short string value in it. Currently I am programatically altering the columns width to 220 and the rows 7th cells height (220 x the height necessary to contain the strig plus an extra amount of height since wordwrap is used) and I only want column 6 cells to do this if necessary for text in them if any. I don't mind doing it programatically measuring strings with  TextRenderer but if there's a better method pls let me know. Also in Chrome on smart phones there is a setting for "Request Desktop Site" which allows Smart Phone to display OSKeyboard for replying and asking questions and such and working with this site FYI.

    La vida loca



    Monday, February 12, 2018 11:49 PM

Answers

  • Hi

    Yes, that's what I figured you meant.

    Here is a complete example (with limited error handling as far as I remember). This example needs the controls as shown in the remarks at the top of the code to be added in the Designer, but, their locations are handled in the code.

    Some of the points you raised in the OP are used in this example, and may assist you to figure things out. It doesn't quite do what you ask in that the word wrap is applied to a column which is also set to Fill. In your case, it sounds like your column would be set to .None and .WrapMode set to True.

    Anyway, here is the code.

    ' A simple example to show the use of a ' DataTable bound to a DataGridView and ' some simple DataTable Compute methods ' and a simple Row Filter ' Form1 with SplitContainer1 - Horiz split ' with DataGridView1 in Panel1 and ' Label1, Label2, Label3 and Label4 ' in Panel2, DateTimePicker1 and Button1 ' Controls are Located by the code, so ' just need To be added As listed here. ' Col3 is derived from Col1 * Col2 ' Col4 is derived from Col1 / Col2 ' NOTE: if Col2 is ZERO then Col4 is infinity Public Class Form1 Dim MyTable As New DataTable("ExampleTable") Dim view As New DataView(MyTable) Dim ContextMenuStrip1 As New ContextMenuStrip Dim DTP As New DateTimePicker Dim path As String = Application.StartupPath & "TestFile.xml" Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing MyTable.WriteXml(path) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Size = New Size(800, 400) Text = "Simple DataTable-DataGridView example" ContextMenuStrip1.Items.Add("Delete Row") ContextMenuStrip1.ShowImageMargin = False AddHandler ContextMenuStrip1.Items(0).Click, AddressOf DeleteRowToolStripMenuItem_Click AddHandler ContextMenuStrip1.Opening, AddressOf ContextMenuStrip1_Opening With MyTable .Columns.Add("Date", GetType(Date)) .Columns.Add("Name", GetType(String)) .Columns.Add("Col1", GetType(Integer)) .Columns.Add("Col2", GetType(Integer)) .Columns.Add("Col3", GetType(Integer), "Col1 * Col2") .Columns.Add("Col4", GetType(Double), "Col1 / Col2") ' use saved file data if one exists If IO.File.Exists(path) Then MyTable.Clear() MyTable.ReadXml(path) Else ' else use some test data instead ' for testing .Rows.Add(Now.AddDays(-11).Date, "One", 11, 12) .Rows.Add(Now.AddDays(-111).Date, "Two", 111, 212) .Rows.Add(Now.AddDays(11).Date, "Three", 112, 12) .Rows.Add(Now.AddDays(111).Date, "Four", 1111, 112) End If End With ' ================ ' some formatting of the DGV columns/cells ' and the Totals Labels With DataGridView1 .Dock = DockStyle.None .Location = New Point(4, 4) .Size = New Size(SplitContainer1.Size.Width - 8, SplitContainer1.Size.Height - 8) .Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top .SelectionMode = DataGridViewSelectionMode.CellSelect .MultiSelect = False .AllowUserToAddRows = True ' assign the DataTable as the DataSource for the DGV .DataSource = view .ContextMenuStrip = ContextMenuStrip1 .Columns("Date").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells .Columns("Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Col4").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Name").DefaultCellStyle.WrapMode = DataGridViewTriState.True .Columns("Date").DefaultCellStyle.Format = "ddd, dd MMM yyyy" .Columns("Col3").DefaultCellStyle.Format = "#.00" .Columns("Col4").DefaultCellStyle.Format = "#.000" Label1.TextAlign = ContentAlignment.TopCenter Label1.Height = 22 Label2.TextAlign = ContentAlignment.TopCenter Label2.Height = 22 Label3.TextAlign = ContentAlignment.TopRight Label3.Height = 22 Label4.TextAlign = ContentAlignment.TopRight Label4.Height = 22 .Columns("Date").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) .Columns("Col3").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) Label3.Padding = New Padding(4, 0, 4, 0) .Columns("Col4").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) Label4.Padding = New Padding(4, 0, 4, 0) .Columns("Date").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Name").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("Col1").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col2").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col3").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col4").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col1").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col2").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col3").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col4").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col3").ReadOnly = True .Columns("Col4").ReadOnly = True .Columns("Date").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .Columns("Date").DefaultCellStyle.ForeColor = Color.Blue .Columns("Col3").DefaultCellStyle.BackColor = Color.PaleGoldenrod .Columns("Col3").DefaultCellStyle.ForeColor = Color.Red .Columns("Col3").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .Columns("Col4").DefaultCellStyle.BackColor = Color.Beige .Columns("Col4").DefaultCellStyle.ForeColor = Color.Green .Columns("Col4").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .AutoResizeRows() End With With Button1 .Text = "Filter" End With With Button1 .TextAlign = ContentAlignment.TopCenter .Location = New Point(12, Label1.Top) .AutoSize = False .Size = New Size(80, Label1.Height) End With With Button2 .TextAlign = ContentAlignment.TopCenter .Location = New Point(Button1.Right + 8, Button1.Top) .AutoSize = False .Size = New Size(80, Label1.Height) End With Dim r1 As Rectangle = DataGridView1.GetCellDisplayRectangle(0, 0, False) With DTP .Format = DateTimePickerFormat.Custom .CustomFormat = "dd MMM yyyy" .Width = r1.Width ' .Font = New Font("Arial", 16) .Visible = False End With DataGridView1.Controls.Add(DTP) AddHandler DTP.Validated, AddressOf DTP_Validated SetValues() SetLabs() End Sub Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError If e.Exception.Message.Contains("correct format") Then ' Notify user - numerical input only MessageBox.Show("These cells only accept numerical values") e.Cancel = True Exit Sub End If End Sub Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As Object, ByVal e As DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged 'update Label locations/sizes SetLabs() End Sub Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit ' update Label values SetValues() DataGridView1.AutoResizeRows() End Sub Sub SetValues() If MyTable.Rows.Count < 1 Then Exit Sub ' set Label values appropriately Label1.Text = MyTable.Compute("sum(Col1)", "").ToString Label2.Text = MyTable.Compute("sum(Col2)", "").ToString Label3.Text = CInt(MyTable.Compute("sum(Col3)", "")).ToString("#.00") Label4.Text = CInt(MyTable.Compute("sum(Col4)", "")).ToString("#.00") SetLabs() End Sub Sub SetLabs() ' align Labels toDGV columns With DataGridView1

          If .RowCount = 0 Then Exit Sub
    Dim r1 As Rectangle = .GetCellDisplayRectangle(2, 0, False) Label1.Width = r1.Width - 8 Label1.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(3, 0, False) Label2.Width = r1.Width - 8 Label2.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(4, 0, False) Label3.Width = r1.Width - 8 Label3.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(5, 0, False) Label4.Width = r1.Width - 8 Label4.Location = New Point(r1.Left + 10, 6) End With End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' invoke a simple Filter on the Table Data ' based on the Date in Row selected Dim d As String = DataGridView1("Date", DataGridView1.CurrentRow.Index).Value.ToString view.RowFilter = "Date = '" & d & "'" End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click ' clear filter view.RowFilter = Nothing End Sub Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) 'get row clicked Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(PointToClient(MousePosition).X, PointToClient(MousePosition).Y) If hit.RowIndex = DataGridView1.NewRowIndex Then ' do no open if on NewRow e.Cancel = True Exit Sub End If If hit.ColumnIndex < 0 Then DataGridView1(0, hit.RowIndex).Selected = True Exit Sub End If DataGridView1(hit.ColumnIndex, hit.RowIndex).Selected = True End Sub Private Sub DeleteRowToolStripMenuItem_Click(sender As Object, e As EventArgs) ' do not allow delete NewRow Dim r As Integer = DataGridView1.CurrentRow.Index If r = DataGridView1.NewRowIndex Then Exit Sub DataGridView1.Rows.RemoveAt(r) SetValues() End Sub Private Sub dataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded ' set a default Date (Today) for NewRow With e.Row .Cells("Date").Value = Now.Date End With End Sub Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If Not e.ColumnIndex = 0 Then DTP.Visible = False dtpRow = -1 Exit Sub End If Dim r1 As Rectangle = DataGridView1.GetCellDisplayRectangle(0, e.RowIndex, False) Dim cd As Date = Now Try cd = CDate(DataGridView1("Date", e.RowIndex).Value) Catch ex As Exception End Try Dim ft As Font = DataGridView1("Date", e.RowIndex).OwningColumn.DefaultCellStyle.Font With DTP .Font = ft .Value = cd.Date .Size = r1.Size Dim h As Integer = r1.Location.Y + (r1.Height - .Height) \ 2 .Location = New Point(r1.Location.X, h) .Visible = True End With dtpRow = e.RowIndex End Sub Dim dtpRow As Integer = 0 Private Sub DTP_Validated(sender As Object, e As EventArgs) If dtpRow < 0 Then Exit Sub DataGridView1("Date", dtpRow).Value = DTP.Value.Date End Sub End Class



    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, February 13, 2018 2:34 AM
    • Marked as answer by Mr. Monkeyboy Wednesday, February 14, 2018 7:08 AM
    Tuesday, February 13, 2018 2:22 AM

All replies

  • Hi

    If you are the one and only Mr.Monkeyboy, then I feel I must be on the wrong track here .........

    However, my answer would have been to use as per this for the column named 'Name', but can be indexed if better.

    .Columns("Name").DefaultCellStyle.WrapMode = DataGridViewTriState.True

    I also put this in the .EndEdit event handler to resize row to accommodate multilines after changes.

    DataGridView1.AutoResizeRow(e.RowIndex)
    

    I must be misunderstanding your question as I can't imagine you are not already fully aware of this.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, February 13, 2018 12:07 AM
    • Proposed as answer by Cor Ligthert Tuesday, February 13, 2018 9:29 AM
    Monday, February 12, 2018 11:56 PM
  • Hi

    If you are the one and only Mr.Monkeyboy, then I feel I must be on the wrong track here .........

    However, my answer would have been to use as per this for the column named 'Name', but can be indexed if better.

    .Columns("Name").DefaultCellStyle.WrapMode = DataGridViewTriState.True

    I also put this in the .EndEdit event handler to resize row to accommodate multilines after changes.

    DataGridView1.AutoResizeRow(e.RowIndex)

    I must be misunderstanding your question as I can't imagine you are not already fully aware of this.


    Regards Les, Livingston, Scotland


    I don't use DGV enough really. I let all cells in a row except the last auto expand horizontally since each contaians a relatively short string. But the last cell in each row is the only one I want staying a certain width and expanding vertically lly to fit a string. Plus I haven't really programmed in about a year so I'm kinda outdated! 😶 And trying to type with a stylus on a smart phone isnt real efficient either.

    La vida loca



    Tuesday, February 13, 2018 12:21 AM
  • Hi

    Confused here.From what you say, I think you must have all columns except the last column set to

    .AutoSizeColumnMode = DataGridViewAutoSizeColumnsMode.Fill

    and you want the last column to expand horizontally to allow string to fit (don't you mean expand vertically to allow word wrap to show the whole string)?

    If all that is true, then the code I posted above would do it.


    Regards Les, Livingston, Scotland

    Tuesday, February 13, 2018 1:23 AM
  • I meant expand vertically for the last cell in any row while maintaining a specific horizontal width (column index 6). I can't display code as I don't have ISP for my PC.


    La vida loca


    Tuesday, February 13, 2018 2:01 AM
  • Hi

    Yes, that's what I figured you meant.

    Here is a complete example (with limited error handling as far as I remember). This example needs the controls as shown in the remarks at the top of the code to be added in the Designer, but, their locations are handled in the code.

    Some of the points you raised in the OP are used in this example, and may assist you to figure things out. It doesn't quite do what you ask in that the word wrap is applied to a column which is also set to Fill. In your case, it sounds like your column would be set to .None and .WrapMode set to True.

    Anyway, here is the code.

    ' A simple example to show the use of a ' DataTable bound to a DataGridView and ' some simple DataTable Compute methods ' and a simple Row Filter ' Form1 with SplitContainer1 - Horiz split ' with DataGridView1 in Panel1 and ' Label1, Label2, Label3 and Label4 ' in Panel2, DateTimePicker1 and Button1 ' Controls are Located by the code, so ' just need To be added As listed here. ' Col3 is derived from Col1 * Col2 ' Col4 is derived from Col1 / Col2 ' NOTE: if Col2 is ZERO then Col4 is infinity Public Class Form1 Dim MyTable As New DataTable("ExampleTable") Dim view As New DataView(MyTable) Dim ContextMenuStrip1 As New ContextMenuStrip Dim DTP As New DateTimePicker Dim path As String = Application.StartupPath & "TestFile.xml" Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing MyTable.WriteXml(path) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Size = New Size(800, 400) Text = "Simple DataTable-DataGridView example" ContextMenuStrip1.Items.Add("Delete Row") ContextMenuStrip1.ShowImageMargin = False AddHandler ContextMenuStrip1.Items(0).Click, AddressOf DeleteRowToolStripMenuItem_Click AddHandler ContextMenuStrip1.Opening, AddressOf ContextMenuStrip1_Opening With MyTable .Columns.Add("Date", GetType(Date)) .Columns.Add("Name", GetType(String)) .Columns.Add("Col1", GetType(Integer)) .Columns.Add("Col2", GetType(Integer)) .Columns.Add("Col3", GetType(Integer), "Col1 * Col2") .Columns.Add("Col4", GetType(Double), "Col1 / Col2") ' use saved file data if one exists If IO.File.Exists(path) Then MyTable.Clear() MyTable.ReadXml(path) Else ' else use some test data instead ' for testing .Rows.Add(Now.AddDays(-11).Date, "One", 11, 12) .Rows.Add(Now.AddDays(-111).Date, "Two", 111, 212) .Rows.Add(Now.AddDays(11).Date, "Three", 112, 12) .Rows.Add(Now.AddDays(111).Date, "Four", 1111, 112) End If End With ' ================ ' some formatting of the DGV columns/cells ' and the Totals Labels With DataGridView1 .Dock = DockStyle.None .Location = New Point(4, 4) .Size = New Size(SplitContainer1.Size.Width - 8, SplitContainer1.Size.Height - 8) .Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top .SelectionMode = DataGridViewSelectionMode.CellSelect .MultiSelect = False .AllowUserToAddRows = True ' assign the DataTable as the DataSource for the DGV .DataSource = view .ContextMenuStrip = ContextMenuStrip1 .Columns("Date").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells .Columns("Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Col4").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill .Columns("Name").DefaultCellStyle.WrapMode = DataGridViewTriState.True .Columns("Date").DefaultCellStyle.Format = "ddd, dd MMM yyyy" .Columns("Col3").DefaultCellStyle.Format = "#.00" .Columns("Col4").DefaultCellStyle.Format = "#.000" Label1.TextAlign = ContentAlignment.TopCenter Label1.Height = 22 Label2.TextAlign = ContentAlignment.TopCenter Label2.Height = 22 Label3.TextAlign = ContentAlignment.TopRight Label3.Height = 22 Label4.TextAlign = ContentAlignment.TopRight Label4.Height = 22 .Columns("Date").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) .Columns("Col3").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) Label3.Padding = New Padding(4, 0, 4, 0) .Columns("Col4").DefaultCellStyle.Padding = New Padding(4, 0, 4, 0) Label4.Padding = New Padding(4, 0, 4, 0) .Columns("Date").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Name").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("Col1").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col2").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col3").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col4").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col1").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col2").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("Col3").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col4").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("Col3").ReadOnly = True .Columns("Col4").ReadOnly = True .Columns("Date").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .Columns("Date").DefaultCellStyle.ForeColor = Color.Blue .Columns("Col3").DefaultCellStyle.BackColor = Color.PaleGoldenrod .Columns("Col3").DefaultCellStyle.ForeColor = Color.Red .Columns("Col3").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .Columns("Col4").DefaultCellStyle.BackColor = Color.Beige .Columns("Col4").DefaultCellStyle.ForeColor = Color.Green .Columns("Col4").DefaultCellStyle.Font = New Font("Arial", 12, FontStyle.Bold) .AutoResizeRows() End With With Button1 .Text = "Filter" End With With Button1 .TextAlign = ContentAlignment.TopCenter .Location = New Point(12, Label1.Top) .AutoSize = False .Size = New Size(80, Label1.Height) End With With Button2 .TextAlign = ContentAlignment.TopCenter .Location = New Point(Button1.Right + 8, Button1.Top) .AutoSize = False .Size = New Size(80, Label1.Height) End With Dim r1 As Rectangle = DataGridView1.GetCellDisplayRectangle(0, 0, False) With DTP .Format = DateTimePickerFormat.Custom .CustomFormat = "dd MMM yyyy" .Width = r1.Width ' .Font = New Font("Arial", 16) .Visible = False End With DataGridView1.Controls.Add(DTP) AddHandler DTP.Validated, AddressOf DTP_Validated SetValues() SetLabs() End Sub Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError If e.Exception.Message.Contains("correct format") Then ' Notify user - numerical input only MessageBox.Show("These cells only accept numerical values") e.Cancel = True Exit Sub End If End Sub Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As Object, ByVal e As DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged 'update Label locations/sizes SetLabs() End Sub Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit ' update Label values SetValues() DataGridView1.AutoResizeRows() End Sub Sub SetValues() If MyTable.Rows.Count < 1 Then Exit Sub ' set Label values appropriately Label1.Text = MyTable.Compute("sum(Col1)", "").ToString Label2.Text = MyTable.Compute("sum(Col2)", "").ToString Label3.Text = CInt(MyTable.Compute("sum(Col3)", "")).ToString("#.00") Label4.Text = CInt(MyTable.Compute("sum(Col4)", "")).ToString("#.00") SetLabs() End Sub Sub SetLabs() ' align Labels toDGV columns With DataGridView1

          If .RowCount = 0 Then Exit Sub
    Dim r1 As Rectangle = .GetCellDisplayRectangle(2, 0, False) Label1.Width = r1.Width - 8 Label1.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(3, 0, False) Label2.Width = r1.Width - 8 Label2.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(4, 0, False) Label3.Width = r1.Width - 8 Label3.Location = New Point(r1.Left + 10, 6) r1 = .GetCellDisplayRectangle(5, 0, False) Label4.Width = r1.Width - 8 Label4.Location = New Point(r1.Left + 10, 6) End With End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' invoke a simple Filter on the Table Data ' based on the Date in Row selected Dim d As String = DataGridView1("Date", DataGridView1.CurrentRow.Index).Value.ToString view.RowFilter = "Date = '" & d & "'" End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click ' clear filter view.RowFilter = Nothing End Sub Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) 'get row clicked Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(PointToClient(MousePosition).X, PointToClient(MousePosition).Y) If hit.RowIndex = DataGridView1.NewRowIndex Then ' do no open if on NewRow e.Cancel = True Exit Sub End If If hit.ColumnIndex < 0 Then DataGridView1(0, hit.RowIndex).Selected = True Exit Sub End If DataGridView1(hit.ColumnIndex, hit.RowIndex).Selected = True End Sub Private Sub DeleteRowToolStripMenuItem_Click(sender As Object, e As EventArgs) ' do not allow delete NewRow Dim r As Integer = DataGridView1.CurrentRow.Index If r = DataGridView1.NewRowIndex Then Exit Sub DataGridView1.Rows.RemoveAt(r) SetValues() End Sub Private Sub dataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded ' set a default Date (Today) for NewRow With e.Row .Cells("Date").Value = Now.Date End With End Sub Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If Not e.ColumnIndex = 0 Then DTP.Visible = False dtpRow = -1 Exit Sub End If Dim r1 As Rectangle = DataGridView1.GetCellDisplayRectangle(0, e.RowIndex, False) Dim cd As Date = Now Try cd = CDate(DataGridView1("Date", e.RowIndex).Value) Catch ex As Exception End Try Dim ft As Font = DataGridView1("Date", e.RowIndex).OwningColumn.DefaultCellStyle.Font With DTP .Font = ft .Value = cd.Date .Size = r1.Size Dim h As Integer = r1.Location.Y + (r1.Height - .Height) \ 2 .Location = New Point(r1.Location.X, h) .Visible = True End With dtpRow = e.RowIndex End Sub Dim dtpRow As Integer = 0 Private Sub DTP_Validated(sender As Object, e As EventArgs) If dtpRow < 0 Then Exit Sub DataGridView1("Date", dtpRow).Value = DTP.Value.Date End Sub End Class



    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, February 13, 2018 2:34 AM
    • Marked as answer by Mr. Monkeyboy Wednesday, February 14, 2018 7:08 AM
    Tuesday, February 13, 2018 2:22 AM
  • I don't use DGV enough really. I let all cells in a row except the last auto expand horizontally since each contaians a relatively short string. But the last cell in each row is the only one I want staying a certain width and expanding vertically lly to fit a string. Plus I haven't really programmed in about a year so I'm kinda outdated! 😶 And trying to type with a stylus on a smart phone isnt real efficient either.

    La vida loca


    Hi Mr.Monkeyboy,

    According to your description, you have many columns in datagridview, and you want to auto resize column width for only one column(Last Column) in datagridview, am I right?

    But I read your post above, I am confused about your goal. For example, I have four columns in datagridview, now i want to auto resize last column width,

    Dim dt As New DataTable
            dt.Columns.Add("Id", GetType(Integer))
            dt.Columns.Add("UserName", GetType(String))
            dt.Columns.Add("Password", GetType(String))
            dt.Columns.Add("Things", GetType(String))
    
            dt.Rows.Add(1, "Admin", "123", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
            DataGridView1.DataSource = dt
            DataGridView1.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

    If you want to auto resize all columns width in datagridview,

     DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.AllCells

    https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autosizecolumnsmode(v=vs.110).aspx

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 13, 2018 7:07 AM
    Moderator
  • I think the first reply from Les must set you on the track. We have this on our website. You are with a normal keyboard smart enough to do the rest. 

    http://www.vb-tips.com/DataGridViewMultiLine.aspx

    I think we agree that "the best" is very subjective so about that I never give an opinion in a forum. 


    Success Cor

    Tuesday, February 13, 2018 9:32 AM
  • I think the first reply from Les must set you on the track. We have this on our website. You are with a normal keyboard smart enough to do the rest. 

    http://www.vb-tips.com/DataGridViewMultiLine.aspx

    I think we agree that "the best" is very subjective so about that I never give an opinion in a forum. 


    Success Cor

    Well I had already attempted others responses but none worked in .net 4.5.1. Also I programatically figured out how to do this as I only want specific rows in column 6, that have strings measured width for the font > 150 to perform this so the rows 7th cell (6) alters to a specific height for only its text.

    Of course I could be wrong in my attempts. However I can not add a row on app launch as added rows after start are saved as an encrypted string in a user setting of type System.Collections.SpecializedStringCollection. and this is not accessed until after a logon dialog is used to show the main form. So I have to use a timer to check a boolean value IfDataGridViewDataExists and then if the password string is blank or not to determine if the dialog exited. As the dialog, if it exits ok paases the password to the main form and prior to it exiting no code can find data in the datagridview cause it doesn't exist till the timer decrypts it. Anyhow I use the DataGridView sorted and cell end edit events to run the code too.

    Sounds cluj'y to me though but it works. I'm going to mark Les's last post as the answer and tomorrow look at it again to see if I missed something previously. I already sold one copy of the app, it's used for storing online account info cryptographically so a user need only remember the password used with the app in order to viw an acct, its user name, pswd, etc rather than having to remember all that or putting the info on a sheet of paper or in a non-encrypted file. Plus the data can be backed up encrypted to a seperate file and restored if/when necessary (original pc app was on breaks, etc). Neighbor asked for it when I was welding up a 8'6" tall yard art dinosaur for them....


    La vida loca

    Wednesday, February 14, 2018 7:07 AM
  • I don't use DGV enough really. I let all cells in a row except the last auto expand horizontally since each contaians a relatively short string. But the last cell in each row is the only one I want staying a certain width and expanding vertically lly to fit a string. Plus I haven't really programmed in about a year so I'm kinda outdated! 😶 And trying to type with a stylus on a smart phone isnt real efficient either.

    La vida loca


    Hi Mr.Monkeyboy,

    According to your description, you have many columns in datagridview, and you want to auto resize column width for only one column(Last Column) in datagridview, am I right?

    But I read your post above, I am confused about your goal. For example, I have four columns in datagridview, now i want to auto resize last column width,

    Dim dt As New DataTable
            dt.Columns.Add("Id", GetType(Integer))
            dt.Columns.Add("UserName", GetType(String))
            dt.Columns.Add("Password", GetType(String))
            dt.Columns.Add("Things", GetType(String))
    
            dt.Rows.Add(1, "Admin", "123", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
            DataGridView1.DataSource = dt
            DataGridView1.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

    If you want to auto resize all columns width in datagridview,

     DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.AllCells

    https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autosizecolumnsmode(v=vs.110).aspx

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I did try that Cherry prior to u posting this and tks for the effort though.

    La vida loca

    Wednesday, February 14, 2018 7:10 AM
  • I think the first reply from Les must set you on the track. We have this on our website. You are with a normal keyboard smart enough to do the rest. 

    http://www.vb-tips.com/DataGridViewMultiLine.aspx

    I think we agree that "the best" is very subjective so about that I never give an opinion in a forum. 


    Success Cor

    Well I had already attempted others responses but none worked in .net 4.5.1. Also I programatically figured out how to do this as I only want specific rows in column 6, that have strings measured width for the font > 150 to perform this so the rows 7th cell (6) alters to a specific height for only its text.

    Of course I could be wrong in my attempts. However I can not add a row on app launch as added rows after start are saved as an encrypted string in a user setting of type System.Collections.SpecializedStringCollection. and this is not accessed until after a logon dialog is used to show the main form. So I have to use a timer to check a boolean value IfDataGridViewDataExists and then if the password string is blank or not to determine if the dialog exited. As the dialog, if it exits ok paases the password to the main form and prior to it exiting no code can find data in the datagridview cause it doesn't exist till the timer decrypts it. Anyhow I use the DataGridView sorted and cell end edit events to run the code too.

    Sounds cluj'y to me though but it works. I'm going to mark Les's last post as the answer and tomorrow look at it again to see if I missed something previously. I already sold one copy of the app, it's used for storing online account info cryptographically so a user need only remember the password used with the app in order to viw an acct, its user name, pswd, etc rather than having to remember all that or putting the info on a sheet of paper or in a non-encrypted file. Plus the data can be backed up encrypted to a seperate file and restored if/when necessary (original pc app was on breaks, etc). Neighbor asked for it when I was welding up a 8'6" tall yard art dinosaur for them....


    La vida loca

    Is this what you mean?

    :)

    Public Class Form3
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(400, 300)
    
            With dgv
                .Size = New Size(460, 200)
                .Location = New Point(20, 20)
                .Font = New Font("Arial", 10, FontStyle.Bold)
                .ColumnCount = 2
                .Columns(0).Name = "Column A"
                .Columns(1).Name = "Column B"
    
                .Rows.Add("This is a value", "")
                .Rows.Add("This is a value", "")
    
                dgv.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True
                dgv.Rows(0).Cells(1).Value = "This is a short value"
                dgv.Rows(1).Cells(1).Value = "This is a long value for testing purposes. The cell will expand vertically to fit the cell text with word wrap."
            End With
    
            TextBox1.Location = New Point(20, 270)
            TextBox1.Size = New Size(460, 30)
    
            NumericUpDown1.Location = New Point(100, 230)
            NumericUpDown1.Maximum = 200
            NumericUpDown1.Minimum = 10
            NumericUpDown1.Increment = 10
            NumericUpDown1.Value = 200
    
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            dgv.Rows(0).Cells(1).Value = TextBox1.Text
            dgv.AutoResizeRows()
        End Sub
    
        Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
            dgv.Columns(1).Width = CInt(NumericUpDown1.Value)
            dgv.AutoResizeRows()
        End Sub
    
        Private Sub dgv_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellValueChanged
            dgv.AutoResizeRows()
        End Sub
    End Class


    PS as Les said for just one row you can I don't see how to do just one cell this way (other than using measure string).

    dgv.Rows(1).DefaultCellStyle.WrapMode = DataGridViewTriState.True


    Wednesday, February 14, 2018 9:50 AM

  • PS as Les said for just one row you can I don't see how to do just one cell this way (other than using measure string).


    Hi

    Yes, a single cell can have Wrap set or unset. See this simple useless code.

    ' Some useless code to illustrate some of
    ' the functions of a DataGridView
    ' WordWrap with AutoReSizeRows
    ' This example needs a Form1 with DataGridView1
    ' 3 Buttons for
    ' (Wrap Cell, Wrap Row And Wrap Columns)
    ' and a CheckBox1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	With DataGridView1
    	  ' some dummy data for testing with
    	  .Rows.Add("This is just some garbage text to help illustrate some characteristics of a DataGridView WordWrap. It is not completely finished as using one Toggle after a previous toggle may need more than 1 click to take effect. This issue,I leave to the dear reader to amend.", "It is a wonderful piece of coding which many mere mortals couldn't achieve with ease, even if they are aged beyond 5 years.", "Many coders have fallen by the wayside in attempting this feat, and their ghosts still haunt the forum.""Some have risen to greatness though and are now regarded as Guro of the month. An accolade given to so few.")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	End With
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    	Dim c As DataGridViewCell = DataGridView1.SelectedCells(0)
    	If Not c.Style.WrapMode = DataGridViewTriState.True Then
    	  c.Style.WrapMode = DataGridViewTriState.True
    	Else
    	  c.Style.WrapMode = DataGridViewTriState.False
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    	Dim c As DataGridViewCell = DataGridView1.SelectedCells(0)
    	If DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True Then
    	  DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.False
    	Else
    	  DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    	Dim c As Integer = DataGridView1.SelectedCells(0).ColumnIndex
    	If DataGridView1.Columns(c).DefaultCellStyle.WrapMode = DataGridViewTriState.True Then
    	  DataGridView1.Columns(c).DefaultCellStyle.WrapMode = DataGridViewTriState.False
    	Else
    	  DataGridView1.Columns(c).DefaultCellStyle.WrapMode = DataGridViewTriState.True
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    Wednesday, February 14, 2018 4:28 PM

  • PS as Les said for just one row you can I don't see how to do just one cell this way (other than using measure string).


    Hi

    Yes, a single cell can have Wrap set or unset. See this simple useless code.

    
    


    Regards Les, Livingston, Scotland

    Les,

    Wish you would show a quick picture of your examples, very easy for us and useful. I am not sure what each button does etc.  :)

    I meant I am not sure if you can have the height change to fit the word wrap for just one cell, if that is what Monkey means. But I guess it does not make sense. 

    I am still not sure exactly what is wanted. If the cell is edited by the user or just displayed once no changing or when and how it is updated etc.


    Monkey,

    A picture of what you want might help if you have not already solved it.

    PS Oh, I guess its the phone problem you cant show images?
    Wednesday, February 14, 2018 5:08 PM
  • Les,

    Wish you would show a quick picture of your examples, very easy for us and useful. I am not sure what each button does etc.  :)

    Hi tommy

    I have amended the code I posted to this to include a 'Reset' of methods prior to each Button use.

    Some images below.

    Amended Code

    ' Some useless code to illustrate some of
    ' the functions of a DataGridView
    ' WordWrap with AutoReSizeRows
    ' This example needs a Form1 with DataGridView1
    ' 3 Buttons for
    ' (Wrap Cell, Wrap Row And Wrap Columns)
    ' and a CheckBox1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	With DataGridView1
    	  .MultiSelect = False
    	  .SelectionMode = DataGridViewSelectionMode.CellSelect
    	  ' some dummy data for testing with
    	  .Rows.Add("This is just some garbage text to help illustrate some characteristics of a DataGridView WordWrap. It is not completely finished as using one Toggle after a previous toggle may need more than 1 click to take effect. This issue,I leave to the dear reader to amend.", "It is a wonderful piece of coding which many mere mortals couldn't achieve with ease, even if they are aged beyond 5 years.", "Many coders have fallen by the wayside in attempting this feat, and their ghosts still haunt the forum.""Some have risen to greatness though and are now regarded as Guro of the month. An accolade given to so few.")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	  .Rows.Add("jhsg adj dhgasd jhd jha JAHD JHA AH HJA ahjd as dhahd ash", "uha fahhfi fisd uhff iudfu uisd df uf f dfsukfsd", "ksakj fkjhg fafk sdaaskj fk fs ksd df fsd sd")
    	End With
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    	ResetToNone()
    	Dim c As DataGridViewCell = DataGridView1.SelectedCells(0)
    	If Not c.Style.WrapMode = DataGridViewTriState.True Then
    	  c.Style.WrapMode = DataGridViewTriState.True
    	Else
    	  c.Style.WrapMode = DataGridViewTriState.False
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    	ResetToNone()
    	Dim c As DataGridViewCell = DataGridView1.SelectedCells(0)
    	If DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True Then
    	  DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.False
    	Else
    	  DataGridView1.Rows(c.RowIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    	ResetToNone()
    	Dim c As DataGridViewCell = DataGridView1.SelectedCells(0)
    	If DataGridView1.Columns(c.ColumnIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True Then
    	  DataGridView1.Columns(c.ColumnIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.False
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).DefaultCellStyle.WrapMode = DataGridViewTriState.True
    	End If
    	If CheckBox1.Checked Then
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    	Else
    	  DataGridView1.Columns(c.ColumnIndex).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
    	End If
    	DataGridView1.AutoResizeRows()
      End Sub
      Sub ResetToNone()
    	' reset to default
    	DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
    	DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
      End Sub
    End Class
    Start Position

    Cell Wrap Toggled

    Row Wrap Toggled

    Column WrapToggled


    Regards Les, Livingston, Scotland

    Wednesday, February 14, 2018 6:11 PM

  • PS as Les said for just one row you can I don't see how to do just one cell this way (other than using measure string).


    Hi

    Yes, a single cell can have Wrap set or unset. See this simple useless code.

    
    


    Regards Les, Livingston, Scotland

    Les,

    Wish you would show a quick picture of your examples, very easy for us and useful. I am not sure what each button does etc.  :)

    I meant I am not sure if you can have the height change to fit the word wrap for just one cell, if that is what Monkey means. But I guess it does not make sense. 

    I am still not sure exactly what is wanted. If the cell is edited by the user or just displayed once no changing or when and how it is updated etc.


    Monkey,

    A picture of what you want might help if you have not already solved it.

    PS Oh, I guess its the phone problem you cant show images?
    I've got it working the way I used. But I plan to try the other methods soon. Currently using iTextSharp to write pdf help file and there's a learning curve. Tks for the efforts. I only want word wrap in column 6 so it expands vertically and all other columns (0 - 5) expand horizontally only even though they will grow vertically if col 6 gros vertically but they will not wrap.

    La vida loca

    Thursday, February 15, 2018 6:45 AM