Results 1 to 3 of 3

Thread: DGV not showing text in cell

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    DGV not showing text in cell

    I've got an unbound DGV with several columns that I am programmatically adding rows to. All working fine, apart from when I try to set a really long string in one of the cells, then that cell just appears blank. The string IS in the cell because if I select the cell and do this:
    vb.net Code:
    1. My.Computer.Clipboard.SetText(CStr(OutputDGV.SelectedCells(0).Value))
    then the string gets copied to the clipboard and I can paste it into Notepad or whatever without a problem. So it is just purely a display issue... but it doesn't seem to make any difference if I resize the cell (horizontally or vertically) and I can't understand why it is doing this.

    The string in question is roughly 7000 characters long, where as strings that are about 400 characters long are displaying fine. I know you are going to say surely you don't need to have 7000 characters in a DGV cell, but this is a reporting application and I'm at the mercy of the data in the database I am querying (which I have no control over) and whilst the majority of the time only very short strings will be loaded from the database, I have to be able to handle scenarios where a large amount of data is there. I don't care if the string gets truncated in the DGV or something (as I have an option to export the DGV contents to CSV, TXT, or HTML) but its just the fact that the cell appears to be completely empty that is a problem.

    Any ideas?

    Thanks
    Chris
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: DGV not showing text in cell

    I have found that this only happens if I make the columns autosize to fit the contents, if I remove the line of code that does that (see below) then the string is displayed

    vb Code:
    1. OutputDGV.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)

    I do need it to resize all other columns automatically though (if worst comes to worst I can just add some special case code to not resize this one column I guess) but the problem is if I double click the edge of the column to expand it to show all contents manually, I get the same problem of the string disappearing...
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: DGV not showing text in cell

    Well I've submitted a Connect bug report (https://connect.microsoft.com/Visual...resized-to-max) but I doubt it will ever be fixed as I guess its not very common to want to show several thousand characters in a DGV cell...

    My workaround for now is to prevent columns from being auto resized to the maximum width, which I do by using the ColumnWidthChanged event to stop any column from ever being wider than 2000 pixels (or whatever it is measured in). Not ideal but its the best I can do for now, at least this way the user can see there is data in there and due to the "..." that automatically gets added to the end of the cell they can see that there is more data than they can see so they will have to export it to file to be able to see all of it.
    vb Code:
    1. Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
    2.      If e.Column.Width > 2000 Then
    3.             e.Column.Width = 2000
    4.      End If
    5. End Sub
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width