
Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
>-----Original Message-----
>Hi Paul,
[quoted text clipped - 24 lines]
>
>.
Sorry, Luke, but this doesn't work. My datagrid is
dynamically generated - not pre determined. I dynamically
build a datatable, and make this the source for the
datagrid. The datatable is not directly obtained from the
database - it comes from a set of objects which either are
made from DB derived data, or other objects made from
these objects. I want to be able to hide columns also,
which is being a real pain too. Columns in the data table
don't have a "No Wrap" property, and so can't be set
there. They also don't have a "visible" propert to make
false. The datagrid only accesses columns by index, and
only indexes the hard coded columns in the page (of which
I have none).
Please help!
Paul.
MSFT - 02 Feb 2004 08:23 GMT
Hi Paul,
If we add DataColmn to the DataGird, we can control the Wrap property of a
column. Please refer to following sample:
Dim dt As New DataTable("MyTable")
Dim dc As New DataColumn("id", System.Type.GetType("System.Int16"))
dt.Columns.Add(dc)
dc = New DataColumn("name", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("age", System.Type.GetType("System.Int16"))
dt.Columns.Add(dc)
Dim dr As DataRow = dt.NewRow()
dr(0) = 1
dr(1) = "Luke"
dr(2) = 35
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 2
dr(1) = "My name is Luke, my id is 2, my age is 36;My name is Luke,
my id is 2, my age is 36"
dr(2) = 36
dt.Rows.Add(dr)
Dim dg As New DataGrid
dg.Visible = True
dg.AutoGenerateColumns = False
Dim dgc As New BoundColumn
dgc.HeaderText = "ID"
dgc.DataField = "id"
dg.Columns.Add(dgc)
dgc = New BoundColumn
dgc.HeaderText = "Name"
dgc.DataField = "name"
dgc.ItemStyle.Wrap = False
dg.Columns.Add(dgc)
dgc = New BoundColumn
dgc.HeaderText = "age"
dgc.DataField = "age"
dg.Columns.Add(dgc)
dg.DataSource = dt
dg.DataBind()
Me.Controls.Add(dg)
'dg.Columns(2).Visible = False
And, as you have seen, to hide a column, we can call "dg.Columns(2).Visible
= False"
Luke
Microsoft Online Support

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Paul N - 02 Feb 2004 17:30 GMT
Thanks very much, Luke - that's my problem solved.
Paul Nelson.