Changing Width of Datagrid (AutoGenerateColumn=true)

G

Gh0st

Hi, hope some1 can help me trying this about a week.

I read the data for my Datagrid into a dataset, convert a little bit
and store the finalresult in another ds from an Access-DB and bind the
data

ds.Tables.Add("Vendor")
With ds.Tables("Vendor").Columns
..Add("Verkäufer")
..Add("Name")
..Add("Umsatz")
..Add("Kunden")
..Add("øKauf")
..Add("Positionen/Kunde")
..Add("Umsatz/Bereich")
End With

query = "SELECT ....."
da.SelectCommand = New OleDb.OleDbCommand(query, cn)
da.Fill(ds, "Salesperson")
....
conversion and "Salesperson"->"Vendor"
....
DataGrid1.DataSource = ds.Tables("Vendor").DefaultView
DataGrid1.DataBind()

And after the DataBind my datagrid1.colums.count is always 0. this is
because of the AutoGenerateColumn=true, i've read.

But i can't figure out how i should change the width of a column.
DataGrid1.Columns(0).ItemStyle.Width = Unit.Pixel(100)
does NOT work, because VB.NET says my Datagrid has 0 Columns.

But if I look at my asp Page I can see the whole Datagrid.

Hope some1 has an idear and perhaps even some code.
 
G

Gh0st

yes i make the with after the databind

I can't do it in the Itemcreated because i want to set the width of
all Columns so the same size the largest Column had.
Like (rough example):
dim width as integer
for i as interger=0 to datagrid1.columns.count
if width < datagrid1.colums(i).width
width=datagrid1.colums(i).width
next

for each column as datacolumn in datagrid1.columns
column.width=width
next

Don't know if the code is exactly correkt but i think you'll know what
i mean.

the Itemcreated is fired everytime a new item is created, ok i can
check there if it is a header and count... but then i still have the
problem with accessing a column in the datagrid. (columns = 0)
 
G

Gh0st

Yeeehaaaw just made it

query = "SELECT Country, ZIP FROM ZIP GROUP BY Country, ZIP"
da.SelectCommand = New OleDb.OleDbCommand(query, cn)
da.Fill(ds, "Country")

Dim col As New BoundColumn
col.HeaderText = "Stadt"
col.DataField = "Country"
DataGrid1.Columns.Add(col)

DataGrid1.DataSource = ds

DataGrid1.DataBind()
DataGrid1.Columns(0).HeaderStyle.Width = Unit.Pixel(200)

this is the way i can change the width like i want. But thx für help Jared
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top