Print Preview ActiveX Active Users: 26 / Visits Today: 26
Highest Active Users: 26
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Print Preview
 Questions about Print Preview
 DataGrid Col Width
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic: richtextbox, please it is urgent Topic Next Topic: Row Hight in Grid Report  

kintyre1
Starting Member

United Kingdom
1 Posts

Posted - 02/15/2004 :  13:06:37  Show Profile  Reply with Quote
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.
Go to Bottom of Page

Waty Thierry
Forum Admin

Belgium
635 Posts

Posted - 02/17/2004 :  08:34:03  Show Profile  Visit Waty Thierry's Homepage  Reply with Quote
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
Go to Bottom of PageGo to Top of Page

Waty Thierry
Forum Admin

Belgium
635 Posts

Posted - 02/17/2004 :  14:38:58  Show Profile  Visit Waty Thierry's Homepage  Reply with Quote
' #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
Go to Bottom of PageGo to Top of Page

makaveiljojo
Starting Member

USA
8 Posts

Posted - 04/15/2014 :  05:44:10  Show Profile  Reply with Quote
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
Go to Bottom of PageGo to Top of Page
  Previous Topic: richtextbox, please it is urgent Topic Next Topic: Row Hight in Grid Report  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000 Version 3.4.02