This is a migrated thread and some comments may be shown as answers.

Format AutoGenerated Columns

1 Answer 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Javid
Top achievements
Rank 1
Javid asked on 09 Jan 2012, 01:34 PM

Hello,

I'm using RadGridView.I need to format the cells of grid like "###,###".Moreover as long as my ItemSource is totally arbitrary, I can not define the columns in xaml or code. However, I know the first column is of string type and the rest are double
I need something like :

public void radGridView1_Loading(e) // or formatting
{
        if(e.ColumnIndex>1)
            e.Cell.Format = "###,###";
}

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
StevenDale
Top achievements
Rank 2
answered on 12 Apr 2012, 08:20 PM

I know this is a late response but others may be looking for the same thing.

You should be able to do the following in RowLoaded event of your RadGridView. This is what I do when I am binding dynamically using a datatable to format my columns. This example formats my date column.

if (e.Row.DataContext is DataRow)
{
for (int i = 0; i < (e.Row.DataContext as DataRow).ItemArray.Count(); i++)
{
if ((e.Row.DataContext as DataRow).ItemArray[i] is DateTime)
{
if (string.IsNullOrWhiteSpace(e.Row.Cells[i].DataColumn.DataFormatString))
e.Row.Cells[i].DataColumn.DataFormatString = "MM/dd/yyyy HH:mm";
}
}
}



Tags
GridView
Asked by
Javid
Top achievements
Rank 1
Answers by
StevenDale
Top achievements
Rank 2
Share this question
or