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

How can I apply different colors to radgridview rows through bindings

5 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vladu Bogdan
Top achievements
Rank 1
Vladu Bogdan asked on 22 Sep 2009, 09:00 AM
Hi all and sorry if my query was already discussed on this forumm but I was unable to find what I'm looking for!

I've started playing with your incredible controls and have seen some diferrent ways of changing row styles for the gridview but, I am trying to bind the value of a column from a dataset (the column name is Color and contains an unsigned integer value) which contains customer's details (customer ids, names, adresses, date of births, customer types, etc.), to the "background" color of the coresponding row depending on the cusotmer type, for example  if customer type is 2 then the color field for the related row is 100, 100 represents the red color, and so on...

Is there a way of doing that, or should I just find out another aproach, the dataset with all the details is set as the item source of the grid as bellow:

radGridView1.ItemsSource = dsCustomerDetails;


Another great thing will be if you can let me now which component from the radgridview control exposes the property which give the color of the row from the grid when I'm editing the control parts templates, I was unable to find the component which give the "row style" in order to try to edit a copy of that template whcih will have a different behave depending on my needs?

Please any help will be greatly appreciated,

thanks alot!

5 Answers, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 25 Sep 2009, 07:31 AM
Hello Vladu,

I have prepared a small sample which hopefully will boost you to the final result. When you browse the app attached you will notice a grid containing personal information (name, address, email, etc.) and a column which contains hex values of colors. Those colors are then used to as a background for each row. I am sure you will have no troubles of extending this logic to parse your unsigned int field and to the color associations to match your case.

As for the component which sets the background of the row - it is named SelectionBackground. I understand that this is a bit poor naming which is a weak point on our part and we will be refactoring that in the future.

All the best,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vladu Bogdan
Top achievements
Rank 1
answered on 25 Sep 2009, 08:57 AM
Hi Kalin and thank you for the sample app you've provided, actually this is not what I was looking to achive, I have already seen that if I use the RowLoaded event I can change the row style, what am I looking for is something more graceful, more like a binding route of doing that... 

Please let me explain you in more details what I have in mind, I am trying to edit the proper / coresponding template of the component / control that has the property that changes the GridViewRow background, I have looped through RadGridView templates but I was unable to locate the template that can be edited in order to bind the background property to a DependancyProperty for example that can have it's value changed either programatically or from the user interface, do you thing that I am on the right route?  It seems to me the path to the control that holds that background property which I want to bind to a DP is so hard to get to it?

I am using Blend to loop through templates as I am no such of a master of xaml coding and get to the point of editing the template of the GridViewItemsControl (not sure if the path is correct, cannot tell from the naming mechanism for sure how to get to the target element) and saw that cannot edit further from GridViewVirtualizingPanel component which I've suspected to be the component that holds the template control I am looking but again I am not sure if the way is the correct one!

It may be usefull if I can output somehow the controls hierarchy from the root (RadGridView) to the child control that holds that property, is there a code support of geting that element?

If the above explination is to poor or unclear please let me know otherwise do you think that is posible to achieve what I am proposing, it may not have a proper meaning to you but if I could edit the related template and bind it to a DP I will then be able to meet some code requirments, I found the binding way more convenient rather to raise the RowLoaded event and put all the buisnes logic in there but if this is the only way, I will resign myself,

thank you very much for all the help until now!
0
Kalin Milanov
Telerik team
answered on 30 Sep 2009, 11:17 AM
Hi Vladu Bogdan,

I have updated the sample to not use the RowLoaded event and rather set the background of the cell through RowStyle binding it to a value in the cell though a converter. Maybe this something which can work better for you.

If you open the sample Blent there is also a GridViewRow and its template for you to browse. There is a bug in our control which causes Blend not to recognize RowStyle and goes not let you edit the row. We are working on a fix and this issue should not be there once Q3 is out.

Regards,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vladu Bogdan
Top achievements
Rank 1
answered on 05 Oct 2009, 08:35 AM
Hi Kalin,

thank you very much for your reply, indeed this is more into what I was looking and this aproach meets the requirments of my work, thanks again, excelent work!
0
M
Top achievements
Rank 1
answered on 11 Jun 2010, 05:01 PM
Another option, if you want to avoid events and have everything done via binding is you create style triggers using RadGridView.Resources within RadGridView and bind its values to data context or member of data context.
Tags
GridView
Asked by
Vladu Bogdan
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Vladu Bogdan
Top achievements
Rank 1
M
Top achievements
Rank 1
Share this question
or