how to Change border color active subitem in listviewdataitem?

7 posts, 0 answers
  1. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 20 Sep 2019 Link to this post

    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.

     

  2. Dimitar
    Admin
    Dimitar avatar
    2926 posts

    Posted 23 Sep 2019 Link to this post

    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.
  3. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 24 Sep 2019 in reply to Dimitar Link to this post

    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?
  4. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 24 Sep 2019 in reply to Khanh Link to this post

    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.

  5. Dimitar
    Admin
    Dimitar avatar
    2926 posts

    Posted 25 Sep 2019 Link to this post

    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.
  6. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 26 Sep 2019 in reply to Dimitar Link to this post

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

  7. Dimitar
    Admin
    Dimitar avatar
    2926 posts

    Posted 27 Sep 2019 Link to this post

    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.
Back to Top