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

2 posts, 0 answers
  1. Craig Broadhead
    Craig Broadhead avatar
    23 posts
    Member since:
    Jul 2010

    Posted 09 Mar 2012 Link to this post

    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
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 14 Mar 2012 Link to this post

    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 >>
Back to Top