Format DataGrid at design time

adwaitjoshi

Active member
Joined
Dec 29, 2005
Messages
38
Programming Experience
1-3
I always forget how to do this. Does someone know how to format a datagrid at design time with all the formatting and then at run time just supply a datasource to it?
 
If you have added a table style to your DataGrid (so individual column styles have been generated), then you can use code such as this to set the Format property of a particular column style.

[C#]
//add format col 3 columnstyle where column 3 holds a date...
DataGridTextBoxColumn dgtbc;
dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[3] as _
DataGridTextBoxColumn;
if(dgtbc != null)
dgtbc.Format = "g"; // or "u" or whatever format you want to see

[VB.NET]
'add format col 3 columnstyle where column 3 holds a date...

Dim dgtbc As DataGridTextBoxColumn
dgtbc = CType(dataGrid1.TableStyles(0).GridColumnStyles(3), _
DataGridTextBoxColumn)
If Not dgtbc is Nothing Then
dgtbc.Format = "g" ' or "u" or whatever format you want to see
End If
 
Back
Top