This is a migrated thread and some comments may be shown as answers.

how to Change border color active subitem in listviewdataitem?

6 Answers 988 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Khanh
Top achievements
Rank 1
Iron
Khanh asked on 21 Sep 2019, 03:17 AM

Hi, I have two questions that need help regarding effects on listview
Question one: I tried changing the border color of active subitem using events: cellformating, VisualItemFormatting but I still haven't found a way to enable it.
Question two: How can I stop highlight current listviewitem? I want after running listview code, there will be no more highlighted items.
I have uploaded photos for you to visualize.
Thank you.

 

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 23 Sep 2019, 10:25 AM

Hello Khanh,

1. You can use the CellFormatting event for this. Here is how to style the current cell: 

private void RadListView1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    var cell = e.CellElement as DetailListViewDataCellElement;

    if (cell != null && cell.Row.Current && cell.Data.Current)
    {
        e.CellElement.BorderColor = Color.Red;                 
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
    }
}

Since the entire row is styled at once you can use the VisualItemFormatting to set the BackColor:

private void RadListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
    e.VisualItem.DrawFill = false;
}

I hope this helps. Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Khanh
Top achievements
Rank 1
Iron
answered on 24 Sep 2019, 04:43 PM
Hi, Dimitar.i get this error when run this line:
var cell = e.CellElement as DetailListViewDataCellElement;

System.InvalidCastException: 'Unable to cast object of type' Telerik.WinControls.UI.DetailListViewHeaderCellElement 'to type' Telerik.WinControls.UI.DetailListViewDataCellElement '.'

and in the second question, I want to be that after selecting the item (highlighted in blue) and I run the code, the item will return to the unselected state. so I thought I couldn't use VisualItemFormatting because I couldn't get an instance of ListViewVisualItemEventArgs.
Here my listview uses breeze theme
Can you check it again for me?
0
Khanh
Top achievements
Rank 1
Iron
answered on 24 Sep 2019, 05:28 PM

Hi, after checking again i made a mistake, i corrected my code and now your code worked for the first question.
with the second question: I have 1 button and button_click event
I want after clicking the button, the itemselected in listview is no longer highlighted so in the button_click code event I want to add a line at the last of procedule like:
sub button_click (...)
'my code
'.....
e.VisualItem.DrawFill = false '<<<<----- 
end sub
I want the effects to return to the same form when the form started

Thanks.

0
Dimitar
Telerik team
answered on 25 Sep 2019, 08:35 AM

Hello Khanh,

You cannot access the visual elements outside of the event handler. You can clear the selection which should have the desired effect: 

private void radButton1_Click(object sender, EventArgs e)
{
    
    radListView1.CurrentItem = null;
    radListView1.CurrentColumn = null;
    radListView1.SelectedItem = null;
}

I hope this helps. Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Khanh
Top achievements
Rank 1
Iron
answered on 26 Sep 2019, 06:56 PM

Hi Dimitar.
I tested it, worked perfectly: D, so I was able to finish my first vsto project with telerik. I am very happy with it.
Thank you as well as the other admin very much.

Have a nice weekend :)

0
Dimitar
Telerik team
answered on 27 Sep 2019, 06:51 AM

Hello Khanh,

I am glad to hear that this works as expected and you have achieved your goals. 

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ListView
Asked by
Khanh
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Khanh
Top achievements
Rank 1
Iron
Share this question
or