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

Problem with image column while scrolling

4 Answers 12 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 09 Apr 2018, 11:21 AM

hi 

why are all fields empty when scrolling

 

        private void dgvTaskFactory_ViewCellFormatting(object sender, CellFormattingEventArgs e) {
          if (e.CellElement is GridHeaderCellElement) {
                e.CellElement.TextWrap = true;
                e.CellElement.TextAlignment = ContentAlignment.BottomLeft;
            } else {
                if (e.CellElement is GridCellElement cell) {
                    if (cell.ColumnInfo.Name == ColumnTitle.GridTasklistMail.priority) {
                        cell.DrawText = false;
                        cell.Image = Image.FromFile(Convert.ToInt32(cell.Value.ToString()) == -1 ? "express.png" : "timable.png");
                    } else {
                        cell.Image = null;
                    }
                }
            }

        }

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 Apr 2018, 11:59 AM
Hi Andre,

Thank you for writing. 

A similar code seems to work fine on my side. The only reason can be that there is no column with that name. 

Here is the code I have tested with:
Image img;
public RadForm1()
{
    InitializeComponent();
    img = Image.FromFile(@"C:\img\delete.png");
    radGridView1.ViewCellFormatting += RadGridView1_ViewCellFormatting;
    radGridView1.Columns.Add(new GridViewTextBoxColumn() { Name = "ImageColumn", HeaderText = "Image Column" });
    for (int i = 0; i < 10; i++)
    {
        radGridView1.Rows.Add("Row" + i);
    }
}
 
private void RadGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement is GridHeaderCellElement)
    {
        e.CellElement.TextWrap = true;
        e.CellElement.TextAlignment = ContentAlignment.BottomLeft;
    }
    else
    {
        if (e.CellElement is GridCellElement cell)
        {
            if (cell.ColumnInfo.Name == "ImageColumn")
            {
                cell.DrawText = false;
                cell.Image = img;
            }
            else
            {
                cell.Image = null;
            }
        }
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andre
Top achievements
Rank 1
answered on 09 Apr 2018, 12:32 PM

hi dimitar

the column name is already correct, because everything is displayed correctly when loading.
the problem occurs only when i have to scroll horizontally. scrolling vertically is no problem i have noticed.

0
Accepted
Dimitar
Telerik team
answered on 10 Apr 2018, 08:32 AM
Hi Andre,

Ok, I was able to see the issue. We are using UI Virtualization which means that cell elements are reused and you will need to reset the DrawText property as well. Here is the code:
private void RadGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    //reset the value first
    e.CellElement.DrawText = true;
 
    if (e.CellElement is GridHeaderCellElement)
    {
        e.CellElement.TextWrap = true;
        e.CellElement.TextAlignment = ContentAlignment.BottomLeft;
    }
    else
    {
        if (e.CellElement is GridDataCellElement cell)
        {
            if (cell.ColumnInfo.Name == "ImageColumn")
            {
                cell.DrawText = false;
                cell.Image = img;
            }
            else
            {
                cell.Image = null;
                
            }
        }
    }
}

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andre
Top achievements
Rank 1
answered on 10 Apr 2018, 05:52 PM

hi dimitar

works perfectly !!

many thanks

andré

Tags
GridView
Asked by
Andre
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Andre
Top achievements
Rank 1
Share this question
or