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

Different cell type in the same Column

1 Answer 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martino
Top achievements
Rank 1
Martino asked on 18 Nov 2011, 04:59 PM
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


1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 21 Nov 2011, 05:16 PM
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.

Tags
GridView
Asked by
Martino
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or