all groups > dotnet compact framework > december 2006 >
You're in the

dotnet compact framework

group:

Column widht in datagrid


Column widht in datagrid Catalin Lungu
12/29/2006 11:46:40 AM
dotnet compact framework:
Hi,
How do I set the column width for a datagrid in NetCF 1. (VS2003)

Tia, C.

RE: Column widht in datagrid Oxcarz
1/1/2007 9:21:01 AM
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

Re: Column widht in datagrid Catalin Lungu
1/2/2007 9:55:57 AM
Thank you very much. It's works fine.

AddThis Social Bookmark Button