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

Extra icon in Grid

6 Answers 315 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lily
Top achievements
Rank 1
Lily asked on 21 Jan 2011, 07:15 PM
Several our grids shows phantom icon in the first line, first column. The icons are in another columns and shown correctly.
Lily

 

6 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 21 Jan 2011, 09:56 PM
Hello Lily,

Can you please provide additional info on this one? Is the first column a custom column? Please provide some additional details on what you are using and how can i replicate this problem.

Or if possible, please create a small test project and add it here, that will ease the process of finding a solution.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 09:57 PM
Hello,

How are you adding the image to the column? I suspect you are adding this via the CellFormatting event. If this is the case, please post your code and I'll take a look at it for you.

CellFormatting
Private Sub rgvPendingItems_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles rgvPendingItems.CellFormatting
    If e.Column.Name = "Party" Then
        e.CellElement.Image = 'Image
    Else
        e.CellElement.Image = Nothing
    End If
End Sub

If you are not using CellFormatting, please let me know
Thanks
Richard
0
Vivek
Top achievements
Rank 1
answered on 21 Jan 2011, 10:10 PM
You are right. 
The image is being added in the Cell Formatting event. 
Below is the code for CellFormatting event. 
ilApprovals is an imagelist.

Thanks,
Vivek

private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
  {
            GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;
            if (e.CellElement.IsCurrent)
            {
                e.CellElement.DrawBorder = false;
                e.CellElement.DrawFill = false;
            }

            if (e.CellElement.Value != null)
            {
                e.CellElement.ToolTipText = e.CellElement.Value.ToString();
            }

            string colName = bnUtil.SafeString(e.CellElement.ColumnInfo.Name).ToLower();
            if (colName == "colapproved")
            {
                e.CellElement.Text = "";
                bool approved = bnUtil.SafeBool(e.CellElement.Value);
                if (approved)
                {
                    e.CellElement.Image = ilApprovals.Images[0];
                }
                else
                {
                    e.CellElement.Image = ilApprovals.Images[1];
                }
            }
        }
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 10:19 PM
Hello,

Be sure to set a value of null for the image for all the other cells. Remember that the RadGridView uses UI Virtualization so cells get re-used and this is why you may be seeing the image appearing in unwanted cells.

private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
  {
            GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;
            if (e.CellElement.IsCurrent)
            {
                e.CellElement.DrawBorder = false;
                e.CellElement.DrawFill = false;
            }
  
            if (e.CellElement.Value != null)
            {
                e.CellElement.ToolTipText = e.CellElement.Value.ToString();
            }
  
            string colName = bnUtil.SafeString(e.CellElement.ColumnInfo.Name).ToLower();
            if (colName == "colapproved")
            {
                e.CellElement.Text = "";
                bool approved = bnUtil.SafeBool(e.CellElement.Value);
                if (approved)
                {
                    e.CellElement.Image = ilApprovals.Images[0];
                }
                else if......
                {
                    e.CellElement.Image = ilApprovals.Images[1];
                }
                else
                {
                    e.CellElement.Image = null;
                }
            }

hope that helps
Richard
0
Vivek
Top achievements
Rank 1
answered on 21 Jan 2011, 10:58 PM
I did not realize that cells are re-used. 
What you suggested worked like a charm.

Appreciate your help.
- Vivek
0
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 11:01 PM
Glad that helped. Please remember to mark as answer
In addition, you can read more about UI Virtualization here

Regards,
Richard
Tags
GridView
Asked by
Lily
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Vivek
Top achievements
Rank 1
Share this question
or