If you're talking about a Windows Control (as opposed to
Web Control), you need to
instantiate "DataGridTableStyle", which contains
a "ColumnStyles" collection. You add members to the
collection for each of the columns that should appear in
your Grid. Once you've done that, you can manipulate
quite a few properties in both DataGridTableStyles and
the collection members for widths, fonts, colors,
borders, etc.
I hope this sample code will give you a basic model. It
uses DataGridTextBoxColumn objects, which is the
easiest. But you can derive your own classes to use as
ColumnStyles, as well.
Private Sub FillDocGrid(ByVal DocID As Integer)
OleDbSelectCommand2.CommandText=SelectDocsCmd &
DocID.ToString & "'"
DocumentsDA.Fill(TechLibDS, "Documents")
DocGrid.DataSource = TechLibDS
DocGrid.DataMember = "Documents"
Dim DocGridTS As New DataGridTableStyle()
DocGridTS.RowHeadersVisible = False
DocGridTS.MappingName = "TechLibDS.Documents"
' MappingName links DataTable columns to the
' ColumnStyles
Dim IDCS As New DataGridTextBoxColumn()
IDCS.MappingName = "ID"
IDCS.HeaderText = ""
IDCS.Width = 0
DocGridTS.GridColumnStyles.Add(IDCS)
Dim DocDateCS As New DataGridTextBoxColumn()
DocDateCS.MappingName = "DocDate"
DocDateCS.HeaderText = "Date"
DocDateCS.Width = 120
DocGridTS.GridColumnStyles.Add(DocDateCS)
Dim TitleCS As New DataGridTextBoxColumn()
TitleCS.MappingName = "Title"
TitleCS.HeaderText = "Document Title"
TitleCS.Width = 400
DocGridTS.GridColumnStyles.Add(TitleCS)
Dim DescCS As New DataGridTextBoxColumn()
DescCS.MappingName = "Description"
DescCS.HeaderText = "Document Descripition"
DescCS.Width = 800
DocGridTS.GridColumnStyles.Add(DescCS)
DocGrid.TableStyles.Clear()
DocGrid.TableStyles.Add(DocGridTS)
End Sub
HTH - there's more details in MSDN
Rich
>-----Original Message-----
>I'd like to know how to control the width of each
>DataGrid's column alone to be different from other
>-----Original Message-----
>I'd like to know how to control the width of each
>DataGrid's column alone to be different from other
columns.
>Note that my DataGrid is binded to a DataTable.
> Thanks
>
>.
>
|