Problem with image column while scrolling

5 posts, 1 answers
  1. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 09 Apr 2018 Link to this post

    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;
                        }
                    }
                }

            }

  2. Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 09 Apr 2018 Link to this post

    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.
  3. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 09 Apr 2018 in reply to Dimitar Link to this post

    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.

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 10 Apr 2018 Link to this post

    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.
  5. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 10 Apr 2018 in reply to Dimitar Link to this post

    hi dimitar

    works perfectly !!

    many thanks

    andré

Back to Top