Print Preview ActiveX Active Users: 75 / Visits Today: 313
Highest Active Users: 99
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
 All Forums
 Print Preview
 Questions about Print Preview
 DataGrid Col Width

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert Email Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert a File

Check here to subscribe to this topic.
   

T O P I C    R E V I E W
kintyre1 Posted - 02/15/2004 : 13:06:37
I need to change the col width on a datagrid at run time, it is easy on a flexgrid but I just can not sort it out on the datagrid.
Please help.
3   L A T E S T    R E P L I E S    (Newest First)
makaveiljojo Posted - 04/15/2014 : 05:44:10
Since I am poor in English, I started to realize here the col means datagrid column. Did the suggestion that Waty Thierry offered help you? I am also quite new to a winforms UI datagrid, the datagrid column problem also aroused my interests.

I'd rather be honest than impressive
Waty Thierry Posted - 02/17/2004 : 14:38:58
' #Mandix Repository#************************************************************
' * Programmer Name : Masino Sinaga
' * WebSite : http://www30.brinkster.com/masinosinaga/
' * E-Mail : masino_sinaga@yahoo.com
' * Date : 07/15/2002
' **********************************************************************
' * Comments : Adjust DataGrids Column Width Based on Longest Field in Underlying Source
' *
' * When you display data from a database to a DataGrid, you will
' * see that DataGrid's columns width cannot adjust to the longest
' * data in the field. This following procedure can fix the problem.
' *
' **********************************************************************
Sub AturLebarKolomDataGrid(dg As DataGrid, _
adoData As Adodc, _
jlhRecord As Integer, _
jlhField As Integer, _
Optional AccForHeaders As Boolean)
'Prosedur untuk menyesuaikan ukuran/lebar kolom DataGrid
'Adjust your DataGrid's columns
'dg = DataGrid
'adData = Adodc control
'jlhRecord = Jumlah record (number of records)
'jlhField = Jumlah field (number of fields)
'AccForHeaders = True or False
Dim row As Long, col As Long
Dim width As Single, maxWidth As Single
Dim saveFont As StdFont, saveScaleMode As Integer
Dim cellText As String
'Langsung keluar dari prosedur jika tidak ada
'record di DataGrid
'If the number of records = 0 then exit from the sub
If jlhRecord = 0 Then Exit Sub
'Simpan huruf yang digunakan oleh form,
'dan sesuaikan ke huruf di DataGrid.
'Save the form's font for DataGrid's font
'Kita membutuhkan ini dengan tujuan untuk
'menggunakan metode dari TextWidth milik form.
'We need this for form's TextWidth method
Set saveFont = dg.Parent.Font
Set dg.Parent.Font = dg.Font
'Sesuaikan ScaleMode = vbTwips untuk form (parent).
'Adjust ScaleMode to vbTwips for the form (parent).
saveScaleMode = dg.Parent.ScaleMode
dg.Parent.ScaleMode = vbTwips
adoData.Recordset.MoveFirst
maxWidth = 0
For col = 1 To jlhField - 1
adoData.Recordset.MoveFirst
If AccForHeaders Then
maxWidth = dg.Parent.TextWidth(dg.Columns(col).Text) + 200
End If
adoData.Recordset.MoveFirst
For row = 1 To jlhRecord
'Ambil teks dari sell DataGrid
'Get the text from the DataGrid's cell
If jlhField = 1 Then
Else
cellText = dg.Columns(col).Text
End If
'Hitung lebarnya, dan tetapkan untuk batas.
'Fix the border...
'Catatan: Tidak berlaku untuk "multiple-line text fields"
'atau teks yang fieldnya mengandung dari banyak baris.
'Not for "multiple-line text"...
width = dg.Parent.TextWidth(cellText) + 200
'Update lebar maksimum jika kita menemukan
'sebuah string yang lebih lebar.
'Update the maximum width if we found the wider string
If width > maxWidth Then
maxWidth = width
dg.Columns(col).width = maxWidth
End If
adoData.Recordset.MoveNext
Next row
'Ubah lebar kolom sekarang...
'Change the column width...
dg.Columns(col).width = maxWidth 'kolom terakhir!
Next col
'Ganti property parent milik DataGrid
'Change the DataGrid's parent property
Set dg.Parent.Font = saveFont
dg.Parent.ScaleMode = saveScaleMode
adoData.Recordset.MoveFirst
End Sub 'End of sub


Come and visit :
www.immoassist.com
www.ppreview.net
www.vbdiamond.com
www.d2dsources.com
www.mandix.com
Waty Thierry Posted - 02/17/2004 : 08:34:03
It is not related to PPreview.
I will check my knowledge base to help you

Come and visit :
www.immoassist.com
www.ppreview.net
www.vbdiamond.com
www.d2dsources.com
www.mandix.com

Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000 Version 3.4.02