Column widht in datagrid

C

Catalin Lungu

Hi,
How do I set the column width for a datagrid in NetCF 1. (VS2003)

Tia, C.
 
G

Guest

first, place a dataGrid control on the form. No need to set any properties at
design time. Then use a helper function to build the dataGrid:

Function CreateDataSource() As ICollection
Dim dr As DataRow
dt.Columns.Add(New DataColumn("col1", GetType(String)))
dt.Columns.Add(New DataColumn("col2", GetType(String)))
dt.Columns.Add(New DataColumn("col3", GetType(String)))

For i As Integer = 0 To 5
dr = dt.NewRow
dr(0) = i.ToString
dr(1) = i.ToString
dr(2) = i.ToString
dt.Rows.Add(dr)
Next

'name the table and map it to the dataGridStyle object:
dt.TableName = "myDT"
Dim gridStyle As New DataGridTableStyle
gridStyle.MappingName = "myDT"

'define a column style for each column:
Dim c1Style As New DataGridTextBoxColumn
c1Style.MappingName = "col1"
c1Style.HeaderText = "Col 1"
c1Style.Width = 90
gridStyle.GridColumnStyles.Add(c1Style)

Dim c2Style As New DataGridTextBoxColumn
c2Style.MappingName = "col2"
c2Style.HeaderText = "Col 2"
c2Style.Width = 40
gridStyle.GridColumnStyles.Add(c2Style)

Dim c3Style As New DataGridTextBoxColumn
c3Style.MappingName = "col3"
c3Style.HeaderText = "Col 3"
c3Style.Width = 90
gridStyle.GridColumnStyles.Add(c3Style)
'add the columnStyles to the DataGrid:
DataGrid1.TableStyles.Add(gridStyle)

Dim dv As New DataView(dt)
Return dv
End Function

Then call this function (from form_load, a button click, etc):

DataGrid1.DataSource = CreateDataSource()

hope that helps.

Ox
 

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

Top