Chris_871 Level: Master

 Registered: 30-11-2002 Posts: 106
|
Re: datagrid column width
Hi
I am using DataGrid control in my windows application. I am changing the column width through DataGridTableStyle class.
Here is the sample function which I am using.
Sub headgrid(ByVal str As String, ByVal dg As DataGrid)
dg.Refresh()
dg.TableStyles.Clear()
Dim TS As New DataGridTableStyle()
TS.MappingName = ds.Tables(str).ToString
Dim colsrno As New DataGridTextBoxColumn()
colsrno.HeaderText = "Sr.No"
' colsrno.ReadOnly = True
colsrno.NullText = ""
colsrno.MappingName = ds.Tables(str).Columns(0).ToString()
colsrno.Width = 40
Dim colDescription As New DataGridTextBoxColumn()
colDescription.HeaderText = "Description"
colDescription.NullText = ""
colDescription.MappingName = ds.Tables(str).Columns(1).ToString()
colDescription.Width = 150
Dim colSolution As New DataGridTextBoxColumn
colSolution.HeaderText = "Solution"
colSolution.NullText = ""
colSolution.MappingName = ds.Tables(str).Columns(2).ToString()
colSolution.Width = 150
Dim colDate As New DataGridTextBoxColumn
colDate.HeaderText = "Date"
colDate.NullText = ""
colDate.MappingName = ds.Tables(str).Columns(3).ToString() 'here you can use the date format.
colDate.Width = 150
TS.GridColumnStyles.Add(colsrno)
TS.GridColumnStyles.Add(colDescription)
TS.GridColumnStyles.Add(colSolution)
TS.GridColumnStyles.Add(colDate)
dg.TableStyles.Add(TS)
End Sub
In the above function str is a table.
I hope that it may help you.
Regards
Chris
|