ListViewDataItem BackColor

2 posts, 0 answers
  1. Simon
    Simon avatar
    13 posts
    Member since:
    Aug 2011

    Posted 09 Dec 2014 Link to this post

    I have two radlistviews on a form. I want to hide the selection color in the first listview when an item is selected in the second listview and vice versa. I have added code to the VisualItemFormatting event to do this. However, selecting an item in the second listview doesn't trigger the VisualItemFormatting event of the first listview, so nothing happens. How do I trigger the VisualItemFormatting event of the first listview? Or is there some other way to do this?
  2. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 12 Dec 2014 Link to this post

    Hello,

    Thank you for writing,

    To reach this kind of behavior we have to additionally subscribe both controls to the GotFocus event. Handling only VisualItemFormatting event won`t work because it is fired only for the control which has focus. Please check the code snippet below:
    public ListViewForm()
    {
        InitializeComponent();
     
        this.PopulateData();
        this.LeftRadListView.GotFocus += LeftRadListView_GotFocus;
        this.LeftRadListView.VisualItemFormatting += LeftRadListView_VisualItemFormatting;
        this.RightRadListView.GotFocus +=RightRadListView_GotFocus;
        this.RightRadListView.VisualItemFormatting += RightRadListView_VisualItemFormatting;
    }
     
    private void LeftRadListView_GotFocus(object sender, EventArgs e)
    {
        this.RightRadListView.ListViewElement.SynchronizeVisualItems();
    }
     
    private void LeftRadListView_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
    {
        if (!this.LeftRadListView.Focused)
        {
            e.VisualItem.DrawFill = false;
            e.VisualItem.DrawBorder = false;
        }
        else
        {
            e.VisualItem.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.VisualItem.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
     
    private void RightRadListView_GotFocus(object sender, EventArgs e)
    {
        this.LeftRadListView.ListViewElement.SynchronizeVisualItems();
    }
     
    private void RightRadListView_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
    {
        if (!this.RightRadListView.Focused)
        {
            e.VisualItem.DrawFill = false;
            e.VisualItem.DrawBorder = false;
        }
        else
        {
            e.VisualItem.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.VisualItem.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
     
    private void PopulateData()
    {
        for (int i = 1; i <= 10; i++)
        {
            this.LeftRadListView.Items.Add("Left " + i);
            this.RightRadListView.Items.Add("Right " + i);
        }
    }

    I hope that this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top