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
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
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?
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.
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
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 :)
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