BackgroundImage/-color ignored?

8 posts, 1 answers
  1. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 13 Feb 2012 Link to this post

    In my RadListView the BackgroundImage (and the Backgroundcolor as well) are ignored.
    ViewType is IconsView, but this doesn't matter because it is not shown in all ViewTypes.
    Is this a bug or what?
  2. Saneesh
    Saneesh avatar
    8 posts
    Member since:
    Feb 2012

    Posted 15 Feb 2012 Link to this post

    Post ur code snippet..along with your Quiery please...
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 15 Feb 2012 Link to this post

    In ctor of my form:
    this.radListView1.BackColor = System.Drawing.Color.Lime;
    Then show the form, but the background is still white.
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 15 Feb 2012 Link to this post

    Hello Froggie,

    Thank you for your question.

    No, this is not an issue. You are not able to see the background image or the back color of the control, because the main element of the control (RadListViewElement) is hiding it. In this case you can either set the back color or the background image of the RadListViewElement, or you can set the back color of RadListViewElement to transparent and then use the properties of the control. The attached screenshot demonstrates how to achieve this.

    I hope you find this information useful. Feel free to ask if you have any additional questions.

    Regards,
    Ivan Todorov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 16 Feb 2012 Link to this post

    1. Thank you for your answer. It (partially) solved my problem.
    2. Why is this so complicated? (I think thats my problem because I don't understand the structure of youre controls.)
    3. Now I have another/a new problem:
      After a DragDrop-event the Backcolor of the ListViewElement is reseted. this occurs immediately after removing a Item from the BindingList where the ListView is bound to.
    Some (pseudo-)code:
    private void Form1_Load(object sender, EventArgs e)
            {          
                    RefreshGrid();
            }
     
    private void RefreshGrid()
            {
                radListView1.SuspendLayout();
                radListView1.BeginUpdate();
     
                radListView1.DataSource = null;
                radListView1.DataSource = f.ViewItems;
     
                radListView1.EndUpdate();
                radListView1.ResumeLayout();
            }
     
     private void radListView1_DragDrop(object sender, DragEventArgs e)
            {
                var droppedPoint = radListView1.ListViewElement.PointFromScreen(new Point(e.X, e.Y));
     
                if (e.Data != null)
                {
                    ListViewDataItem draggedListViewDataItem = e.Data.GetData(typeof(ListViewDataItem)) as ListViewDataItem;
                    if (draggedListViewDataItem != null)
                    {
                       //PinboardViewItem is my Business-class
                        var draggedPinboardViewItem = draggedListViewDataItem.DataBoundItem as PinboardViewItem;
                        PinboardViewItem droppedPinboardViewItem = null;
     
                        //f.ViewItems is the BindingList
                        var indexOfDraggedItem = f.ViewItems.IndexOf(draggedPinboardViewItem);
                        int indexOfDroppedItem;
     
                        var droppedVisualItem = findPinboardVisualItem(droppedPoint) as BaseListViewVisualItem;
                        if (droppedVisualItem != null)
                        {
                            droppedPinboardViewItem = droppedVisualItem.Data.DataBoundItem as PinboardViewItem;
                            indexOfDroppedItem = f.ViewItems.IndexOf(droppedPinboardViewItem);
                        }
                        else
                        {
                            indexOfDroppedItem = f.ViewItems.Count - 1;
                        }                  
     
                       //BackColor is still Lime
                        f.ViewItems.Remove(draggedPinboardViewItem);
                        //BackColor is still reseted to default-value
                       f.ViewItems.Insert(indexOfDroppedItem, draggedPinboardViewItem);
                    }
                }
            }

    Why is the Backcolor reseted?

    Edit:

    • I'm using the Theme "Windows 7"
    • the BackColor of the RadListView is still Lime, but the BackColor of RadListViewElement is reseted to White. <- Why?
  7. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 20 Feb 2012 Link to this post

    Hello Froggie,

    Indeed, the structure of our controls may seem complicated at first, but this way a lot of customization abilities are allowed.

    As to your issue with the back color being reset, I have tested the sample project you have sent in a thread named "scroll Listview while dragging item". The reason for resetting the back color to white is the following code:
    private void radListView1_SelectedItemChanged(object sender, EventArgs e)
    {
        if (lastSelectedItem != null)
        {
            lastSelectedItem.Owner.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            lastSelectedItem.Owner.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
        }
        //...

    The Owner of a ListViewDataItem is RadListViewElement - the main element of the control and by calling the ResetValue method, the specified properties are reset to their default value. Removing the ResetValue calls fixes this issue.

    I hope you find this helpful. Should you have any further questions, do not hesitate to ask.

    Kind regards,
    Ivan Todorov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 20 Feb 2012 Link to this post

    Thank you for your reply.
    This solved my issue (within this thread).

    I just copied the code from other examples.
  9. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 21 Feb 2012 Link to this post

    Hello Sebastian,

    We are glad to hear that our assistance has helped you. Write back if you have additional questions.

    Greetings,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready