Can't hide pesky checkboxes

3 posts, 0 answers
  1. Nick
    Nick avatar
    2 posts
    Member since:
    Sep 2012

    Posted 17 Oct 2012 Link to this post

    I'm using a listview with custom items to display formatted data from our database.

    For some reason, I can't seem to get rid of the pesky checkboxes for each item. I've got the following properties defined...at this point both in the visual editor as well as in code that runs after the form on load method.

    lvProgramGoals.ViewType = ListViewType.IconsView;
    lvProgramGoals.FullRowSelect = true;
    lvProgramGoals.AllowEdit = false;
    lvProgramGoals.AllowRemove = false;           
    lvProgramGoals.ShowCheckBoxes = false;


    Guessing there is something happening with how I'm creating and configuring the custom items. 

    using:

    private void lvProgramGoals_VisualItemCreating(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
    {
         e.VisualItem = new CustomVisualItem();       
    }

    I initialize this class (modeled after the Telerik custom item demo)

    class CustomVisualItem : IconListViewVisualItem
    {
        private StackLayoutPanel titleLayout;
        private StackLayoutPanel stackLayout;
     
        private LightVisualElement nameElement;
        private LightVisualElement descriptionElement;
        private LightVisualElement dateRange;
     
        public CustomVisualItem()
        {
            base.CreateChildElements();
     
            titleLayout = new StackLayoutPanel();
            titleLayout.Orientation = Orientation.Horizontal;
            titleLayout.Size = new System.Drawing.Size(200, 30);
     
            nameElement = new LightVisualElement();
            nameElement.TextAlignment = ContentAlignment.MiddleLeft;
            nameElement.TextWrap = true;
            titleLayout.Children.Add(nameElement);
     
            dateRange = new LightVisualElement();
            dateRange.TextAlignment = ContentAlignment.MiddleRight;
            titleLayout.Children.Add(dateRange);
     
            stackLayout = new StackLayoutPanel();
            stackLayout.Orientation = Orientation.Vertical;
     
            stackLayout.Children.Add(titleLayout);
     
            descriptionElement = new LightVisualElement();
            descriptionElement.TextAlignment = ContentAlignment.BottomCenter;
            stackLayout.Children.Add(descriptionElement);
     
            stackLayout.Size = new Size(200, 60);
     
            this.Children.Add(stackLayout);
     
            this.GradientStyle = GradientStyles.Gel;
     
        }
        protected override void SynchronizeProperties()
        {
            base.SynchronizeProperties();           
     
            this.nameElement.Text = Convert.ToString(this.Data[ProgramGoals.COLUMN_NAME]);
            this.descriptionElement.Text = Convert.ToString(this.Data[ProgramGoals.COLUMN_DESCRIPTION]);
     
            //TODO: convert date format to MM/dd/yyyy
            string dateStr =
                this.Data[ProgramGoals.COLUMN_START].ToString() +
                " to " +
                this.Data[ProgramGoals.COLUMN_END].ToString();
            this.dateRange.Text = Convert.ToString(dateStr);
        }
        protected override Type ThemeEffectiveType
        {
            get { return typeof(SimpleListViewVisualItem); }
        }
    }


    Obviously something, somewhere, is overriding my definition that checkboxes should not be visible, but I can't seem to track it down.

    Any help is appreciated. More code can be provided if need be, but wanted to provide the "most relevant" snippets first.

    Additionally, for bonus appreciation, I'm seeing the following (new to Telerik, so probably some noobie issues):
    - I'm binding to the listview using a List<Entities> from MS Entity Framework. No matter what I seem to do, the list of entities seems to be overlaid on the visual elements shown above to get messy overlap. Ideally I would hide the data from each item with the exception of the data flowing through the custom visual elements
    - I've tried a variety of NotifyParentOnMouseInput and ShouldHandleMouseInput configurations, but I still am not able to click on a list item to select. It could be that clicking a row automatically processes the checkbox instead of selecting the item? I'll know once I resolve the issue above. I am however able to use the keyboard up and down arrows to move up and down the list, selecting items as I go.
  2. Nick
    Nick avatar
    2 posts
    Member since:
    Sep 2012

    Posted 17 Oct 2012 Link to this post

    Isn't that the way it always goes. 2 hours bashing my head against the wall, 15 framing this question, and then less than 5 minutes later I fix it.

    public CustomVisualItem()
    {
        //base.CreateChildElements();

    commented out the base method for creating child elements and the checkboxes magically disappear.


    Still having an issue with getting item selection working again, in case anyone has any thoughts...
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 19 Oct 2012 Link to this post

    Hello Nick,

    Thank you for contacting us.

    The CreateChildElements method is called by the base constructor of RadElement and you should override it to create any custom elements (this is not obligatory and you can use the constructor for creating elements as in your case). However, if you call the base.CreateChildElements from your constructor and not from the override, then the base child elements (the checkbox) are duplicated.

    As to the issue with the selection, you should set the ShouldHandleMouseInput property to false for all LightVisualElements you are using:
    public CustomVisualItem()
    {
        titleLayout = new StackLayoutPanel();
        titleLayout.Orientation = Orientation.Horizontal;
        titleLayout.Size = new System.Drawing.Size(200, 30);
     
        nameElement = new LightVisualElement();
        nameElement.TextAlignment = ContentAlignment.MiddleLeft;
        nameElement.TextWrap = true;
        nameElement.ShouldHandleMouseInput = false;
        titleLayout.Children.Add(nameElement);
     
        dateRange = new LightVisualElement();
        dateRange.TextAlignment = ContentAlignment.MiddleRight;
        dateRange.ShouldHandleMouseInput = false;
        titleLayout.Children.Add(dateRange);
     
        stackLayout = new StackLayoutPanel();
        stackLayout.Orientation = Orientation.Vertical;
     
        stackLayout.Children.Add(titleLayout);
     
        descriptionElement = new LightVisualElement();
        descriptionElement.TextAlignment = ContentAlignment.BottomCenter;
        descriptionElement.ShouldHandleMouseInput = false;
        stackLayout.Children.Add(descriptionElement);
     
        stackLayout.Size = new Size(200, 60);
     
        this.Children.Add(stackLayout);
     
        this.GradientStyle = GradientStyles.Gel;
    }

    Additionally, to prevent displaying the default text of the item, you can set this.Text to an empty string:
    protected override void SynchronizeProperties()
    {
        base.SynchronizeProperties();
     
        //...
     
        this.Text = "";
    }

    To prevent overlapping the text of your LightVisualElements, you need to increase the size of the items. To do this, you can either set a larger size to the ItemSize property or allow the icons to size automatically by settings the AllowArbitraryItemHeight property to true.

    I hope you find this useful. Should you have any additional questions, do not hesitate to ask.

    Regards,
    Ivan Todorov
    the Telerik team
    You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
Back to Top