943,865 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1696
  • VB.NET RSS
Feb 3rd, 2009
0

Show all text in datagrid

Expand Post »
Now that I can see the data in the datagrid, I realize that the size of the fields is too small - the customerid and customer name fields both could use expanding so that I can see all of the text. Is there a way to programmatically extend the length of the field so that it can show the entire string?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 3rd, 2009
0

Re: Show all text in datagrid

Something like this?
It will expand the last column in the datagridview. You can edit it to your needs :=)

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub DataGridView1_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete
  2.  
  3. Dim _DGV As DataGridView = DirectCast(sender, DataGridView)
  4. _DGV.Columns(_DGV.ColumnCount - 1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
  5. End Sub
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Feb 3rd, 2009
0

Re: Show all text in datagrid

To help you a little more:

You also can add a ContextMenuStrip to your solution and respond on the rightclicking of a user into one of the columns in your datagrid.
For example, if the user rightclicks into a column a menuitem will be shown with "show all data". If clicked, that particular column will be autosized.

Add the variabele _ActiveColumn to the general declaration section.
Add a contextmenu to your solution with 1 item "Show all data"

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Private _ActiveColumn As Integer = 0
  3.  
  4.  
  5. Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
  6. _ActiveColumn = e.ColumnIndex
  7.  
  8. If e.Button = Windows.Forms.MouseButtons.Right Then
  9. Me.ContextMenuStrip1.Show(Me.DataGridView1, New Point(e.X, e.Y))
  10. End If
  11.  
  12. End Sub
  13.  
  14. Private Sub ShowAllDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowAllDataToolStripMenuItem.Click
  15. For Each oCol As DataGridViewColumn In Me.DataGridView1.Columns
  16. If oCol.Index = _ActiveColumn Then
  17. oCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
  18. Else
  19. oCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
  20. End If
  21. Next
  22. End Sub
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Feb 3rd, 2009
0

Re: Show all text in datagrid

I need to look back at what I did with asp.net and try to figure out the differences in datagrid from forms to asp
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 3rd, 2009
0

Re: Show all text in datagrid

Ok I've finally gotten to look at these snippets.... 4Advanced, works like a charm....

Will keep the right click option for another time
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: VB 2008 INSERT into MS Access Error
Next Thread in VB.NET Forum Timeline: how to deploy vb.net 2003 project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC