Question

I want to display date into grid(devexpress) where the column namely ColumnB is fixed which is of type string, here i want to display all type of data into the column for example shown below:

Example:

if(columnname == 'empname')
{
   columnB =  reader["empname"].ToString() != null ? reader["empname"].ToString() : ""; 
}

else if ( columnname == 'empdate')
{
   //my try
 Datetime temp = Convert.ToDateTime(reader["empdate"])!= null ? Convert.ToDateTime(read["empdate"]): null; 
 columnB = temp.ToString();    //columnB is of string type
}

Here in the "else if" part, I am not getting how do i convert it into string to display in the same column of the grid.

Was it helpful?

Solution

You may try this:

<DataGrid AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding TheDate, StringFormat={}{0:MM/dd/yyyy}}" />
    </DataGrid.Columns>
</DataGrid>

And if you dont want to use the above method then you may try with string.Format()

string.Format("{0:dd MM yyyy}", date);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top