This is a migrated thread and some comments may be shown as answers.
Change Image in GridViewImageColumn
6 Answers 368 Views
This is a migrated thread and some comments may be shown as answers.
Raja
Top achievements
Rank 1
Raja asked on 03 Feb 2009, 10:43 PM
Hi,
     I have 4 columns in RadGridView. 
   
   column0---->ImageColumn   
   column1 ---> ImageColumn
   column2---> textColumn   ---> hidden column
   column3--->textColumn    ----> hidden column

Based on the value in the text column  (column2) i want to change the image in the (column0).

Based on the value in the text column  (column3) i want to change the image in the (column1).

Most probably i have 5 different   values comming into each textColumn.
 
Currently i implemented this by handling viewRowformatting event .

I see a drastic sluggish when user scrolls through the Gridview. Please suggest a better way to do this.

Thank you,
Raja.

6 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 05 Feb 2009, 01:19 PM
Hello Raja,

Thank you for contacting us.

The bottleneck when using images is the loading time. I suggest you loading all images before processing the gird. In addition, the CellFormatting event is a better place to customize cells. Please consider the following sample code:

ImageList imagesList = new ImageList(); 
 
imagesList.Images.Add(Resources.red); 
imagesList.Images.Add(Resources.green); 
imagesList.Images.Add(Resources.blue); 
 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement.ColumnIndex == 1) 
    { 
        if ((decimal)e.CellElement.RowInfo.Cells["Hidden1"].Value % 2 == 0) 
        { 
            e.CellElement.Image = imagesList.Images[0]; 
        } 
        else if ((decimal)e.CellElement.RowInfo.Cells["Hidden1"].Value % 3 == 0) 
        { 
            e.CellElement.Image = imagesList.Images[1]; 
        } 
        else 
        { 
            e.CellElement.Image = imagesList.Images[2]; 
        } 
    } 
 

Should you have any further questions, feel free to write us back.

Regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Raja
Top achievements
Rank 1
answered on 05 Feb 2009, 04:33 PM
Hi Jack,

               Thank you for the solution. I missed that imagelist part. Awesome and wonderfull.

Thank you,
Raja
0
Christian
Top achievements
Rank 1
answered on 07 Aug 2012, 01:26 PM
HI,
I use the WinForms version 726. The event CellFormatting fires correctly. But the entry of an image in the cell does not work. It does not display the graphic. Is there a bug in the version?
Here is an excerpt from my code:

private void gvMitarbeiterBestand_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            try
            {
                GridDataCellElement dataCell = e.CellElement as GridDataCellElement;
                if (dataCell != null && dataCell.ColumnInfo.Name == "Ausgang")
                {
                    GridViewRowInfo zeile = dataCell.RowInfo;
                    if (zeile != null)
                    {
                        clsPersonal mitarbeiterZeile = zeile.DataBoundItem as clsPersonal;
                        if (mitarbeiterZeile != null && !formatierteEintraege.Contains(mitarbeiterZeile))
                        {
                            formatierteEintraege.Add(mitarbeiterZeile);
  
                            if (personallisteVerwendungOffenAbgang != null)
                            {
                                bool abgang = personallisteVerwendungOffenAbgang.Contains(mitarbeiterZeile);
                                if (abgang)
                                {
                                    e.CellElement.DrawText = false;
                                    e.CellElement.Image = Berlin.Polizei.PADUA.Properties.Resources.doorIn;
                                    e.CellElement.BackColor = Color.Blue;
                                }
                                else
                                {
                                    e.CellElement.ResetValue(LightVisualElement.DrawTextProperty, Telerik.WinControls.ValueResetFlags.Local);
                                     
                                }
                              }
                            if (personallisteVerwendungAdV != null)
                            {
                                bool andereADV = (personallisteVerwendungAdV.Contains(mitarbeiterZeile) || mitarbeiterZeile.IstAktuellAbwesend);
                                AbwesendAnzeigen(zeile, andereADV);
                            }
  
                        }
                    }
                }
                }
            catch (Exception ex)
            {
                Berlin.Polizei.PADUA.GUI.AllgemeineFunktionen.SystemFehlerAnzeigen(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
0
Stefan
Telerik team
answered on 10 Aug 2012, 06:35 AM
Hi,

Your question has already been answered in the support thread you've opened. Please, see our answer there for more information.

We kindly ask you to use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Thank you for your understanding.Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Fariba
Top achievements
Rank 1
answered on 13 Aug 2015, 10:10 AM

Hi

I added GridViewImageColumn to my grid

and then on  grid_CellFormatting I wrote below code

    
            if (e.Column.Name == "StatusDescription")
            {
                PreOrders order = (PreOrders)e.Row.DataBoundItem;

                e.CellElement.ImageLayout = ImageLayout.Center;
                switch (order.Status)
                {

                    case PreOrderStatusEnum.NotSend:
                        e.CellElement.Image = null;
                        break;
                    case PreOrderStatusEnum.Send:
                        e.CellElement.Image = Properties.Resources.Send;
                        break;
                    case PreOrderStatusEnum.SendWithError:
                        e.CellElement.Image = Properties.Resources.errorImage;
                        break;
                    case PreOrderStatusEnum.SendSuccesfully:
                        e.CellElement.Image = Properties.Resources.sendSuccesfully;
                        break;
                }
                grid.Invalidate();
            }

which set suitable image depends on condition to cell

but the image does not shown immediately and need to up-down on row or go out from cell  

what should I do to solve the problem

thx

Fariba

0
Stefan
Telerik team
answered on 14 Aug 2015, 10:10 AM
Hello Fariba,

You can try to subscribe to the CellFormatting event at an earlier point of time e.g. at design time, or prior setting/adding the grid's DataSource/Rows.

Also, the grid.Invalidate() call should not be added in this event, so you can remove it.

If you still have issues, please open a support ticket and provide us with a project we can reproduce the experienced issue and we will look into it.

I hope this helps.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Raja
Top achievements
Rank 1
Answers by
Jack
Telerik team
Raja
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Stefan
Telerik team
Fariba
Top achievements
Rank 1
Share this question
or