Show all text in datagrid

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Show all text in datagrid

 
0
  #1
Feb 3rd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Show all text in datagrid

 
0
  #2
Feb 3rd, 2009
Something like this?
It will expand the last column in the datagridview. You can edit it to your needs :=)

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Show all text in datagrid

 
0
  #3
Feb 3rd, 2009
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"

  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Show all text in datagrid

 
0
  #4
Feb 3rd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Show all text in datagrid

 
0
  #5
Feb 3rd, 2009
Ok I've finally gotten to look at these snippets.... 4Advanced, works like a charm....

Will keep the right click option for another time
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC