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

GridView Conditional Column Values

5 Answers 273 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Glen
Top achievements
Rank 1
Glen asked on 02 Jun 2009, 07:48 AM
Hi,

Please bear with me as I am a newbie to WPF and we are evaluating RadGridView as part of a new development project. I

a question on how to use conditional values within a row on the grid.
 

I have a grid which is bound to a simple data table, contacts. Now contacts has several different columns that represent different phone numbers. I also have  a column that has a "default contact mode" that does what it basically says it is used to identify which phone number should be used as a default contact number.

 

How do I define a column that shows the default contact number, that is I do not want to show say all the different phone number columns, just the column that is defined in the "default contact mode". Bearing in mind that this default contact mode will be different for different records.

 

For example I have a data set that looks like:

Name    Phone1    Phone2    Contact Using
Joe        123412    432112    Phone1
Jane      999999    777777    Phone2
Jack       666666    333333    Phone1

So the Grid would look something like

Name    Contact No
Joe        123412
Jane      777777
Jack       666666

Hope that make sense :)

Any help would be greatly appreciated.

 

Glen    

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 02 Jun 2009, 09:29 AM
Hello Glen,

Thank you for the interest in our controls for WPF.
I have prepared  a small example resembling your scenario. Please see the project attached.

Note: The logic to decide which phone to display is placed inside the Convert method of a small custom value converter ( see PhoneDisplayConverter.cs); This converter is used in the binding of the 'Phone' column. The approach using an  IValueCnverter is standard when you need to manipulate data before displaying it in RadGridView. Any custom business logic can be placed in the Convert method.

In more complex scenarios you may also use another approach : Place your own user control within the cell. Provided you get access to the underlying data through the DataContext you have unlimited options to display any content depending on values - for example display the alternative phone as a tooltip.

Let me know if you have any troubles adapting this to your project.
In case you have any questions while evaluating our WPF suite don't hesitate to contact us.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Glen
Top achievements
Rank 1
answered on 03 Jun 2009, 09:47 PM
Hi,

Thanks for such a quick response, that makes perfect sense and works exactly as we wanted it to. There is one issue, on the column where we use the converter, in the example we say it is Contact No, we noticed that we can not use the filtering or grouping functionality that comes with the gridview (which we like heaps by the way!). Is this a known limitation or is there a way to get around this?

Regards,
Glen
0
Pavel Pavlov
Telerik team
answered on 05 Jun 2009, 02:03 PM
Hello Glen,

Unfortunately this is a known limitation of the RadGridView. For our future releases we are planning to extend the API of RadGridView columns with properties like  'sort member path' , 'filter member' path etc. These will solve such issues.
Meanwhile I  would suggest some data manipulation in the business layer rather than in the UI layer.  Something like ruining a query on the datatable to transform it  before binding to the RadGridView.

Let me know if you need further assistance.

All the best,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Pankaj
Top achievements
Rank 1
answered on 03 Jun 2011, 09:31 AM
Hi Telerik,

I want the grid to be default sorted on the converted column. How can I do this..?

Thanks,
Pankaj
0
Pavel Pavlov
Telerik team
answered on 03 Jun 2011, 10:11 AM
Hi Pankaj,

The solution is as follows :
Expose the converted value in your data as additional property. Then use the SortMemberPath to point to that property.

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Glen
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Glen
Top achievements
Rank 1
Pankaj
Top achievements
Rank 1
Share this question
or