Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Setting date format for bound column
posted

ver. 2010 R1 Winforms

I am trying to set the date format for a DateTime column that is being loaded from a SQL Server result set. Of course SQL is sending the full date and time (ie 1/1/2000 12:00.00AM) but I want to display only "1/1/2000".

I have set the column .Format string to "d" and a number of other format options and the grid still displays the raw text coming from SQL Server without formatting. None of the columns on the grid are editable.

Here is my code:

//Load datagrid.DataSource = ds;
grid.DataMember = "Table";
grid.DataBind();

//Set format
grid.DisplayLayout.Bands[0].Columns["MyDate"].Format = "d";

 

I have tried placing the formatting line in the InitializeLayout event handler but it made no difference. Other column properties such as .Hidden work just fine in the context above. It is the .Format that is ignoring anything I put in it.

Thanks.

Eric