It's Urgent !! Plz Help

3 posts, 0 answers
  1. Keyur Raval
    Keyur Raval avatar
    2 posts
    Member since:
    Sep 2009

    Posted 21 Sep 2009 Link to this post

    Hi,

    I am trying to use Telerik Silverlight gridview and have a specific requirement.

    1) Number of columns are dynamic on my gridview, which I am adding dynamically

    2) On the "RowLoaded' event I want to access cell template for every column's cell for the loading row and assign some data template and data context to that ( Or simply content), previously I was using MS DataGrid and doing it as below.

     FrameworkElement element = myDataGrid.Columns[0].GetCellContent(e.Row);
     FrameworkElement datagridCell = GetParent(element, typeof(DataGridCell)); //GetParent is resursive method to get parent
    DataGridCell cell = (DataGridCell)result;
    cell.Content = MyDataModel for that cell;

    Same thing I am trying to achieve with GridView control from Telerik . Please advise me to the appropriate direction.

    Thanks
  2. Keyur Raval
    Keyur Raval avatar
    2 posts
    Member since:
    Sep 2009

    Posted 22 Sep 2009 Link to this post

    Any suggestions, sample code ?

    Thanks

  3. DevCraft banner
  4. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 22 Sep 2009 Link to this post

    Well, generating dynamic columns is quite simple

    Here's  a piece of code that should do the trick
    for(int i=0;i<yourcolumns.Count -1;i++) 
          GridViewDataColumn column = new GridViewDataColumn() {Header = yourcolumns[i].Header, DataType = yourcolumns[i].type}; 
          YourRadGrid.Columns.Add(column);
    }
     



    About the Cell Template of a column, I guess it depends if your style applies to all the cells of a particular columns, in which case something like that would work :

    column.CellTemplate= yourTemplate;

    If the cell template depends on the row, then, in the RowLoaded Event method, try this

    foreach(GridViewCellBase in e.Row.Cells)
    {
            cell.Template = yourTemplate
    }


Back to Top