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

BackgroundImage/-color ignored?

7 Answers 168 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Froggie
Top achievements
Rank 1
Froggie asked on 13 Feb 2012, 10:11 AM
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?

7 Answers, 1 is accepted

Sort by
0
Saneesh
Top achievements
Rank 1
answered on 15 Feb 2012, 01:03 PM
Post ur code snippet..along with your Quiery please...
0
Froggie
Top achievements
Rank 1
answered on 15 Feb 2012, 01:10 PM
In ctor of my form:
this.radListView1.BackColor = System.Drawing.Color.Lime;
Then show the form, but the background is still white.
0
Ivan Todorov
Telerik team
answered on 15 Feb 2012, 06:28 PM
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 >>
0
Froggie
Top achievements
Rank 1
answered on 16 Feb 2012, 09:15 AM
  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?
0
Accepted
Ivan Todorov
Telerik team
answered on 20 Feb 2012, 02:54 PM
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 >>
0
Froggie
Top achievements
Rank 1
answered on 20 Feb 2012, 03:54 PM
Thank you for your reply.
This solved my issue (within this thread).

I just copied the code from other examples.
0
Nikolay
Telerik team
answered on 21 Feb 2012, 04:21 PM
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 >>
Tags
ListView
Asked by
Froggie
Top achievements
Rank 1
Answers by
Saneesh
Top achievements
Rank 1
Froggie
Top achievements
Rank 1
Ivan Todorov
Telerik team
Nikolay
Telerik team
Share this question
or