Click here to Skip to main content
15,891,951 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: How to add option (none) and (new) to itembinding combobox Pin
Loveisasea18-Dec-11 15:57
Loveisasea18-Dec-11 15:57 
GeneralRe: How to add option (none) and (new) to itembinding combobox Pin
Pete O'Hanlon18-Dec-11 19:36
mvePete O'Hanlon18-Dec-11 19:36 
AnswerRe: How to add option (none) and (new) to itembinding combobox Pin
Mycroft Holmes18-Dec-11 16:14
professionalMycroft Holmes18-Dec-11 16:14 
QuestionGetting binding expression out of a DataGridTemplateColumn's CellTemplate in code-behind Pin
Nicolai Schrade13-Dec-11 21:53
Nicolai Schrade13-Dec-11 21:53 
QuestionSub menu Pin
columbos1492712-Dec-11 3:47
columbos1492712-Dec-11 3:47 
AnswerRe: Sub menu Pin
Pete O'Hanlon12-Dec-11 4:04
mvePete O'Hanlon12-Dec-11 4:04 
QuestionHotkey Implementation Pin
gmeehan12-Dec-11 2:47
gmeehan12-Dec-11 2:47 
QuestionBinding SL DataGrid column to looked up property value Pin
Ravi Bhavnani11-Dec-11 14:25
professionalRavi Bhavnani11-Dec-11 14:25 
[Edit: fixed typo in code]

I've recently started tinkering with Silverlight and am trying to figure out how to do something that should be pretty straightforward - i.e. display a looked up value in a DataGrid column.  For the purpose of simplicity, let's assume I want to display a collection of Employee records.  Each Employee contains an Id (int) and JobId (int).  The data grid should display the employee's ID and the job name (not its ID).

The only solution I can think of is to use a value converter (JobIdToJobNameConverter) that uses a static JobsProvider class that contains the mapping of job IDs to names.

<data:DataGridTextColumn
       Header="Employee ID"
       Binding={"Binding EmployeeId"}>
<data:DataGridTextColumn
       Header="Job Name"
       Binding="{Binding EmployeeJobId, Converter={StaticResource JobIdToJobNameConverter}}">


The converter looks like this:

public class JobIdToJobNameConverter : IValueConverter
{
    public object Convert
        (object value,
         Type targetType,
         object parameter,
         CultureInfo culture)
    {
        Job job = JobsProvider.GetJobs().FirstOrDefault
                      (p => p.JobId.Equals ((int) value));
        return job == null ? string.Empty : job.JobName;
    }

    public object ConvertBack
        (object value,
         Type targetType,
         object parameter,
         CultureInfo culture)
    {
        return DependencyProperty.UnsetValue;
    }
}


While this works, it seems there's probably a smarter solution.  A gentle nudge in the right direction would be much appreciated.

Thanks,

/ravi
My new year resolution: 2048 x 1536
Home | Articles | My .NET bits | Freeware
ravib(at)ravib(dot)com


modified 11-Dec-11 23:48pm.

AnswerRe: Binding SL DataGrid column to looked up property value Pin
Mycroft Holmes11-Dec-11 18:49
professionalMycroft Holmes11-Dec-11 18:49 
GeneralRe: Binding SL DataGrid column to looked up property value Pin
Ravi Bhavnani12-Dec-11 1:48
professionalRavi Bhavnani12-Dec-11 1:48 
GeneralRe: Binding SL DataGrid column to looked up property value Pin
Mycroft Holmes12-Dec-11 12:08
professionalMycroft Holmes12-Dec-11 12:08 
QuestionChanges made in visual studio do not show in browser Pin
don_biglia11-Dec-11 12:00
don_biglia11-Dec-11 12:00 
AnswerRe: Changes made in visual studio do not show in browser Pin
Abhinav S11-Dec-11 18:35
Abhinav S11-Dec-11 18:35 
GeneralRe: Changes made in visual studio do not show in browser Pin
don_biglia16-Dec-11 7:52
don_biglia16-Dec-11 7:52 
GeneralRe: Changes made in visual studio do not show in browser Pin
Saksida Bojan18-Dec-11 9:43
Saksida Bojan18-Dec-11 9:43 
QuestionError: Class not registered (Exception from HRESULT: 0x80040154) Pin
Mostafa Sabeti10-Dec-11 22:17
Mostafa Sabeti10-Dec-11 22:17 
AnswerRe: Error: Class not registered (Exception from HRESULT: 0x80040154) Pin
thatraja11-Dec-11 19:52
professionalthatraja11-Dec-11 19:52 
QuestionWPF Radio Button Group Behavior Pin
Eric Woodruff10-Dec-11 15:19
professionalEric Woodruff10-Dec-11 15:19 
AnswerRe: WPF Radio Button Group Behavior Pin
SledgeHammer0110-Dec-11 17:51
SledgeHammer0110-Dec-11 17:51 
Questionhow to hide particular grid. Pin
SRKSHOME9-Dec-11 5:41
SRKSHOME9-Dec-11 5:41 
AnswerRe: how to hide particular grid. Pin
Abhinav S9-Dec-11 23:15
Abhinav S9-Dec-11 23:15 
QuestionDataGrid databinding to List<> properties of an object Pin
Member 84745799-Dec-11 3:21
Member 84745799-Dec-11 3:21 
AnswerRe: DataGrid databinding to List properties of an object Pin
Wayne Gaylard9-Dec-11 5:17
professionalWayne Gaylard9-Dec-11 5:17 
QuestionDependencyProperty doesn't find items in Resource Dictionary Pin
Member 76693458-Dec-11 7:46
Member 76693458-Dec-11 7:46 
QuestionHow to make muti-geometryModel3D to make different colors in trangle Pin
derek09198-Dec-11 2:51
derek09198-Dec-11 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.