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

RadListDataItem backcolor

13 Answers 287 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Giovanni Riccò
Top achievements
Rank 1
Giovanni Riccò asked on 18 Nov 2010, 04:31 PM
Hi,

I could easily change the RadListDataItem ForeColor by setting its ForeColor property, but I can't find out the way to change its backcolor, instead. What should I do?

Thanks, 
Giovanni

13 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 11:01 PM
Hi,

Well, you can change the BackColor property but I'd advise against doing it as you will then loose the style that is associated with the theme for selecting items.
If you want to, then you can change the backcolor in this way:
For Each item As RadListDataItem In Me.RadListControl1.Items
    item.VisualItem.SetValue(LightVisualElement.BackColorProperty, System.Drawing.Color.Red)
    item.VisualItem.SetValue(LightVisualElement.GradientStyleProperty, GradientStyles.Solid)
Next

but in my view, you'd be better off creating a theme for your items in Visual Style Builder. You can find out more about VSB at this link

hope that helps
richard
0
Richard Slade
Top achievements
Rank 2
answered on 21 Nov 2010, 08:28 PM
Hello

Did this help? If so, please mark as answer so others can find the solution too
regards,
Richard
0
Giovanni Riccò
Top achievements
Rank 1
answered on 22 Nov 2010, 09:12 AM
Hi Richard,

this didn't help, because VisualElement property is null, so I get an exception while attempting to set its background color.
I need an alternative.

All the best,
Giovanni
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 10:07 AM
Hello,

I'd advise using the Visual Stye Builder as above to build a new theme that has a background colour that you want to use. If you would like to use the code posted above however, then if you post me a sample of your code then I will happily take a look at it for you.

Thanks
Richard
0
Giovanni Riccò
Top achievements
Rank 1
answered on 22 Nov 2010, 10:50 AM
Hi Richard,

I thought that there would be a simple way of doing this, just as for the ForeColor:

RadListControl radList = new RadListControl();
foreach(Object myObject in myList)
{
RadListDataItem item = new RadListDataItem();
radList.Items.Add(item);
//I can't access item.BackColor, only Font or ForeColor
item.ForeColor = Color.Red;
item.DataBoundItem = myObject;
}

I can't follow the same way because BackColor property is not exposed, and item.VisualItem is null. Is Visual Style Builder the only way?

All the best,
Giovanni
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 10:54 AM
Hi,

Straight after adding the items in the loop that you have in your code, please can you try adding this loop to set the colour. The VisualItem should not be null in this case.

foreach (RadListDataItem item in this.radList.Items) {
    item.VisualItem.SetValue(LightVisualElement.BackColorProperty, System.Drawing.Color.Red);
    item.VisualItem.SetValue(LightVisualElement.GradientStyleProperty, GradientStyles.Solid);
}

Richard

EDIT// I'd still say that going down the VSB route would be best though to avoid incompatibilities.
0
Giovanni Riccò
Top achievements
Rank 1
answered on 22 Nov 2010, 11:45 AM
Hi Richard,

the VisualItem property is still null, even after the addItem loop. I understand that the only way is VSB, isn't it?
Could I suggest you to expose BackColor property just as ForeColor?

Best regards,
Giovanni
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 11:52 AM
Hello,

I don't work for Telerik. I'm just another user of the forums, but if you have a feature suggestion you can request one via a support ticket.

Can you confirm if you are using a RadDropDownList or a RadListControl
Your code indicates you are using a RadListControl, but I have the feeling you are using a RadDropDownList. Please can you confirm.
Thanks
Richard
0
Giovanni Riccò
Top achievements
Rank 1
answered on 22 Nov 2010, 11:55 AM
Hi,

I'm using a RadListControl as you can see.

Giovanni
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 11:57 AM
Hello,

Please subscribe to the VisualItemFormatting event and add the code below

private void radListControl1_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    args.VisualItem.SetValue(LightVisualElement.BackColorProperty, System.Drawing.Color.Red);
    args.VisualItem.SetValue(LightVisualElement.GradientStyleProperty, GradientStyles.Solid);
}

Let me know if this works
thanks
Richard
0
Giovanni Riccò
Top achievements
Rank 1
answered on 22 Nov 2010, 05:00 PM
Hi Richard,

this works!

Thanks a lot,
Giovanni
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 05:02 PM
Excellent, Glad to have been able to help
Richard
0
Peter
Telerik team
answered on 23 Nov 2010, 04:42 PM
Hi Giovanni, I am glad to hear that this solved the issue. In case you need further assistance, please do not hesitate to contact us.

Richard, thank you for sharing your solution with the community.

Sincerely yours, Peter
the Telerik team
Get started with RadControls for WinForms with numerous videos and detailed documentation.
Tags
General Discussions
Asked by
Giovanni Riccò
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Giovanni Riccò
Top achievements
Rank 1
Peter
Telerik team
Share this question
or