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

How can I set column icon (not header icon) through code?

1 Answer 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Craig Broadhead
Top achievements
Rank 1
Craig Broadhead asked on 09 Mar 2012, 11:07 AM
Hi All,

I use datatable as datasource to connect to gridview. Now I would like all content in column 2 have an icon. What do I need to do ?

Thanks

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 14 Mar 2012, 10:01 AM
Hi Craig,

Thank you for writing.

If the images are coming from your data source, you can use the GridViewImageColumn.
If you want to have icon and text or only icon, you can use the CellFormatting event. Here is an example:
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
  if (e.Row is GridViewDataRowInfo)
  {
    e.CellElement.Image = myImage;
    e.CellElement.TextImageRelation = TextImageRelation.ImageBeforeText;
    e.CellElement.ImageAlignment = ContentAlignment.MiddleLeft;
    e.CellElement.TextAlignment = ContentAlignment.MiddleLeft;
  }
}

I hope this will be useful for you. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Craig Broadhead
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or