Strange behavior of CustomCell inside a RadCheckedListBox when scrolling

1 Answer 110 Views
CheckedListBox
Francesco
Top achievements
Rank 1
Francesco asked on 21 Feb 2023, 11:03 AM

Hello,

I have followed the tutorials and I was able to add a CustomCell made of a RadColorBox, this is working perfectly fine as long as the number of columns in the ListBox does not cause the horizontal scroll bar to appear. When this happens, and the user scrolls to show the other columns, the RadColorBox disappears initially and, by debugging what's happening, I see that it's "changing" the cell looping between all the columns in the rows.

This is the starting state

This is what happens when I scroll right untill the first column goes out of view then back in starting position

This is what happens if i keep scrolling left and right, the ColorBox is in the last column

If I keep scrolling left and right

Please note that this "scrolling" ColorBox is possible only because I have commented a line in the custom control

        public override bool IsCompatible(ListViewDetailColumn data, object context)
        {
            //if (data.Name != "Colore")
            //{
            //    return false;
            //}
            return base.IsCompatible(data, context);
        }

If I uncomment the name check, the ColorBox disappears until I have scrolled left and right enough times to allow it to go back to the first column, by debugging the data.Name value I see that it's "moving" from one column to another

This is the Creating event and I am adding the custom cell only if the cell is "Colore", exactly like in the examples, can anyone help me fix this strange behaviour?

        private void listEventi_CellCreating(object sender, Telerik.WinControls.UI.ListViewCellElementCreatingEventArgs e)
        {
            DetailListViewDataCellElement cell = e.CellElement as DetailListViewDataCellElement;
            if (cell != null && cell.Data.Name == "Colore")
            {
                var newCell = new CustomDetailListViewDataCellElement(cell.RowElement, e.CellElement.Data);
                newCell.FormParent = this;
                e.CellElement = newCell;
            }
        }

Thank you in advance for any suggestion

1 Answer, 1 is accepted

Sort by
-1
Dinko | Tech Support Engineer
Telerik team
answered on 23 Feb 2023, 02:36 PM

Hello Franz,

Thank you for the provided details.

The custom cell derives from the DetailListViewDataCellElement class. This class is compatible with every column. To make this work it is necessary to create another DetailListViewDataCellElement which is not compatible with your custom item. You can apply the second custom cell to the rest of the columns.

public class RegularCell : DetailListViewDataCellElement
{
    public RegularCell(DetailListViewVisualItem owner, ListViewDetailColumn column) : base(owner, column)
    {
    }
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(DetailListViewHeaderCellElement);
        }
    }
    public override bool IsCompatible(ListViewDetailColumn data, object context)
    {
        if (data.Name != "Color")
        {
            return true;
        }
        return false;
    }
}

For your convenience, I have created a sample project to demonstrate the above approach. I have placed a button but the solution is applied to each custom element. You can find the project attached to this reply.

As a side note, I notice that this is not mentioned in the article. I have logged an internal item in our backlog to update the article to mention this behavior.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Francesco
Top achievements
Rank 1
commented on 03 Mar 2023, 07:33 AM | edited

Hello Dinko,

I have tested your suggestion but the problem remains, I guess there is a bug in the ColorBox, because when I scroll the picker part disappears, but looking at the cell I can still see

Can you give it a try using a ColorBox? It should be easy to replace the button with it, I'll add my custom cell code to make things even easier.

 

I have also attached a sample project showcasing the problem.

Thank you and best regards

Franz


public class CustomDetailListViewDataCellElement : DetailListViewDataCellElement
    {
        private RadColorBoxElement colorBox;

        public CustomDetailListViewDataCellElement(DetailListViewVisualItem owner,
            ListViewDetailColumn column) : base(owner, column)
        {
        }

        protected override void CreateChildElements()
        {
            base.CreateChildElements();

            this.colorBox = new RadColorBoxElement();
            this.colorBox.ValueChanged += ColorBox_ValueChanged;
            this.colorBox.ColorDialog.ColorDialogForm.ShowBasicColors = true;
            this.colorBox.ColorDialog.ColorDialogForm.ShowCustomColors = false;
            this.colorBox.ColorDialog.ColorDialogForm.ShowHEXColorValue = false;
            this.colorBox.ColorDialog.ColorDialogForm.ShowProfessionalColors = false;
            this.colorBox.ColorDialog.ColorDialogForm.ShowSystemColors = false;
            this.colorBox.ColorDialog.ColorDialogForm.ShowWebColors = false;
            this.Children.Add(colorBox);
        }

        private void ColorBox_ValueChanged(object sender, EventArgs e)
        {
            var rowView = this.Row.DataBoundItem as EventoUtenza; //change with your data type

            var oldValue = rowView.Colore; //change with the color field on the datatype

            rowView.Colore = colorBox.Value;
        }

        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(DetailListViewHeaderCellElement);
            }
        }

        public override void Synchronize()
        {
            base.Synchronize();
            this.Text = "";
            var rowView = this.Row.DataBoundItem as EventoUtenza; //change with your data type
            this.colorBox.Value = rowView.Colore;
        }

        public override bool IsCompatible(ListViewDetailColumn data, object context)
        {
            if (data.Name != "Colore")
            {
                return false;
            }
            return base.IsCompatible(data, context);
        }
    }

Dinko | Tech Support Engineer
Telerik team
commented on 06 Mar 2023, 01:59 PM

Thank you for the provided project.

There is a typo in the RegularCell -> IsCompatible method. The property which needs to be checked is Colore, not Color.

public class RegularCell : DetailListViewDataCellElement
{
    public RegularCell(DetailListViewVisualItem owner, ListViewDetailColumn column) : base(owner, column)
    {
    }
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(DetailListViewHeaderCellElement);
        }
    }
    public override bool IsCompatible(ListViewDetailColumn data, object context)
    {
        if (data.Name != "Colore")
        {
            return true;
        }
        return false;
    }
}

Francesco
Top achievements
Rank 1
commented on 08 Mar 2023, 07:19 AM

Damn, that really slipped out of my view, fixing the typo fixed the problem.

There is still a small glitch while scrolling horizontally, the color box goes over the checkbox, but that's not too big of a problem

Thank you very much for your help Dinko

Dinko | Tech Support Engineer
Telerik team
commented on 08 Mar 2023, 09:55 AM

This behavior comes from the fact the input element of the RadColorBox is always visible. What you could try is to show the RadColorBox only in edit mode. In non-edit mode, you can show only a rectangle with the color. When the user clicks F2, you can show the RadColorBox. You can check the Editor's overview article to get familiar with the editing functionality of the control. You can also check the Custom Editors help article which demonstrates how to create a custom editor.
Tags
CheckedListBox
Asked by
Francesco
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or