Different cell type in the same Column

2 posts, 0 answers
  1. Martino
    Martino avatar
    1 posts
    Member since:
    Nov 2011

    Posted 18 Nov 2011 Link to this post

    Hi,

    in the same column, I can have 2 different types of cells?

    i have this need:

    Col1      Col 2     Col 3
    text text text
    text text text
    text text Image
    text text Image

    Thank


  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 21 Nov 2011 Link to this post

    Hello Martino,

    You cannot have different cell types for different rows. However, you can create a custom cell which contains all possible elements and just hide and show different elements upon a condition. Please, consider that the default data cell is enough in the described scenario where the difference is between text and image. I prepared a sample demonstrating this:
    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridDataCellElement cell = e.CellElement as GridDataCellElement;
        if (cell != null && cell.ColumnInfo.Name == "Name")
        {
            object value = cell.RowInfo.Cells["Check"].Value;
            bool isChecked = value != null ? (bool)value : false;
            if (isChecked)
            {
                e.CellElement.Text = "";
                e.CellElement.Image = Resources.file;
            }
            else
            {
                e.CellElement.Text = cell.Value != null ? cell.Value.ToString() : "";
                e.CellElement.Image = null;
            }
        }
    }

    I hope it helps. If you need further assistance, do not hesitate to write back.
     
    Greetings,
    Jack
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Back to Top