This is a migrated thread and some comments may be shown as answers.
ListViewDataItem BackColor
1 Answer 25 Views
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 10 Dec 2014, 03:16 AM
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?

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 12 Dec 2014, 05:18 PM
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.

 
Asked by
Simon
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or