Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

DataGrid - problem autosize

[es] :: .NET :: DataGrid - problem autosize

[ Pregleda: 2680 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mmilinca

Član broj: 57773
Poruke: 60
82.208.209.*



Profil

icon DataGrid - problem autosize02.11.2005. u 12:03 - pre 224 meseci


Koristim VisualStudio 2003 za razvoj windows ( a ne web) aplikacije.

Zelim da rezultat upita nad bazom prikazem tako da mi sirina kolone odgovara sirini podatka.

U VS 2005 se to resava jednim korakom


dvgStatus.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

gde je dvgStatus tipa DataGridView

Kako to da uradim u VS 2003
 
Odgovor na temu

Oliver Klaćik
Vice President, Thunder Road Software
Inc.
Stara Pazova

Član broj: 34059
Poruke: 242
80.93.231.*

Sajt: www.thunderroadsoftware.c..


Profil

icon Re: DataGrid - problem autosize03.11.2005. u 08:59 - pre 224 meseci
Pokušavao sam sinoć nešto u vezi sa tim, ali mislim da je u .NET Framework-u 1.x to nemoguće. Ipak nisam 100% siguran. Potraži u MSDN-u metod DataGridColumnStyle.GetPreferredSize, pa ćeš možda preko njega moći to da uradiš, ali jedino 'pešaka'. Znači da petljom prođeš sve zapise, nađeš najširi i prema njemu podesiš širinu kolone.
Oliver 'FAQ' Klaćik
 
Odgovor na temu

mmilinca

Član broj: 57773
Poruke: 60
82.208.209.*



Profil

icon Re: DataGrid - problem autosize04.11.2005. u 10:19 - pre 224 meseci
hvala na pomoci
 
Odgovor na temu

serbianmorpheus
Nenad Pavlovic
.Net Developer
Beograd

Član broj: 6872
Poruke: 13
*.yubc.net.

ICQ: 36724223


Profil

icon Re: DataGrid - problem autosize04.11.2005. u 17:21 - pre 224 meseci
Evo malo coda :


Public Sub AutoSizeTable()
Dim numCols As Integer
numCols = DS.Tables(0).Columns.Count
Dim i As Integer
i = 1
Do While (i < numCols - 1)
AutoSizeCol(i)
i = (i + 1)
Loop
End Sub
Public Sub AutoSizeCol(ByVal col As Integer)
Dim width As Single
width = 0
Dim numRows As Integer
numRows = DS.Tables(0).Rows.Count
Dim g As Graphics
g = Graphics.FromHwnd(DataGrid1.Handle)
Dim sf As StringFormat
sf = New StringFormat(StringFormat.GenericTypographic)
Dim size As SizeF
Dim i As Integer
i = 0
Do While (i < numRows)
size = g.MeasureString(DataGrid1(i, col).ToString, DataGrid1.Font, 500, sf)
If (size.Width > width) Then
width = size.Width
End If
i = (i + 1)
Loop
g.Dispose()
DataGrid1.TableStyles(0).GridColumnStyles(col).Width = CType(width, Integer)
End Sub
 
Odgovor na temu

[es] :: .NET :: DataGrid - problem autosize

[ Pregleda: 2680 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.