Gentlemen:
Can anyone tell me how to programmatically change the Width to 15 of column number 6 on Datagrid1 and the format to currency?
Thanks
Andy
Printable View
Gentlemen:
Can anyone tell me how to programmatically change the Width to 15 of column number 6 on Datagrid1 and the format to currency?
Thanks
Andy
You should add a DatagridTableStlye to your datagrid and then the datagridtextboxcolumns and datagridboolcolumns. Then you can set the width and format. As an alternative you can format the data at dataset level but i am afraid there is no other way to set the width of the columns as the properties of default DatagridTableStyle of datagrid (that is created when you just set the datagrid datasource) is not accessible. Dont know if that means anything to you, and please ppl correct me if i am wrong.
Could you please tell me if this is what you mean?
Code:Dim dgStyle as DataGridTableStyle
Dim dgTableStyle As New DataGridTableStyle()
Me.DataGrid1.TableStyles.Clear()
Dim colStyle1 As New DataGridTextBoxColumn()
With colStyle1
.Alignment = HorizontalAlignment.Left
.HeaderText = "Name"
.MappingName = "EmployeeName"
.Width = 50
End With
dgTableStyle.GridColumnStyles.Add(colStyle1)
dgTableStyle.MappingName = "tblEmployees"
Me.DataGrid1.TableStyles.Add(dgTableStyle)
Yes. But i think you dont need this :
Me.DataGrid1.TableStyles.Clear() if you set the datagrid datasource at last. However not sure about it.
Lunatic3:
How do you set the format of this column to Currency$
Code:Dim dgStyle as DataGridTableStyle
Dim dgTableStyle As New DataGridTableStyle()
Me.DataGrid1.TableStyles.Clear()
Dim colStyle1 As New DataGridTextBoxColumn()
With colStyle1
.Alignment = HorizontalAlignment.Left
.HeaderText = "Cost"
.MappingName = "ItemCost"
.Width = 20
End With
dgTableStyle.GridColumnStyles.Add(colStyle1)
dgTableStyle.MappingName = "tblEmployees"
Me.DataGrid1.TableStyles.Add(dgTableStyle)
c represents the local currency format. Look here for details.VB Code:
With colStyle1 .Format("c") '
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemwindowsformsdatagridtextboxcolumnclassformattopic.htm