Home All Groups Group Topic Archive Search About
Author
23 Aug 2006 7:30 AM
Kaushik Gadani
I am using .Net Framework 1.1 and ASP.Net & VB.Net.

I want to get width of each column after databind method. Please note I have
not assigned width design time, as I am not knowing how many columns will be
available. So at the runtime I am binding to datasource and later on I need
each column's width to set another control. Also there is a width property
available, but it gives always zero (0) in its value. Please help me to find
width in pixel.

Thanks in Advance.

- Kaushik

Author
23 Aug 2006 8:46 AM
Peter Proost
Hi the datagrid has a PreferredColumnWidth property which gives you the
default column width, you can also use the DataGridTableStyle, for example:

Dim myCon As New SqlConnection("Data Source=server;Initial
Catalog=db;Integrated security=True")
Dim myDs As New DataSet
Dim myDa As New SqlDataAdapter("select * from ib015", myCon)

myCon.Open()
myDa.Fill(myDs, "ib015")
myCon.Close()

Dim tableStyle As DataGridTableStyle
tableStyle = New DataGridTableStyle
tableStyle.MappingName = "ib015"

' let the dataGrid use the tablestyle and bind it to our table
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(tableStyle)
DataGrid1.DataSource = myDs.Tables("ib015")

For i As Integer = 0 To myDs.Tables("ib015").Columns.Count - 1
        MsgBox(DataGrid1.TableStyles("ib015").GridColumnStyles(i).Width)
Next


Hope this helps

Greetz, Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Show quoteHide quote
"Kaushik Gadani" <KaushikGad***@discussions.microsoft.com> schreef in
bericht news:7438B715-B4F4-46CB-A32B-69169CB2691C@microsoft.com...
> I am using .Net Framework 1.1 and ASP.Net & VB.Net.
>
> I want to get width of each column after databind method. Please note I
have
> not assigned width design time, as I am not knowing how many columns will
be
> available. So at the runtime I am binding to datasource and later on I
need
> each column's width to set another control. Also there is a width property
> available, but it gives always zero (0) in its value. Please help me to
find
> width in pixel.
>
> Thanks in Advance.
>
> - Kaushik