2

I have a big problem. I try to bind my WPF DataGrid to a table, created with inner join. I have created a class for the info to convert successfully:

public class NeshtoSi
{
    public NeshtoSi() { }

    public string ssn;
    public string name;
    public string surname;
}

And then I create the inner-joined tables. Still when I assign the ItemsSource and all values are transferred properly, but the DataGrid does not visualize them.

var dd = from d in dataContext.Medical_Examinations
         join p in dataContext.Patients on d.SSN equals p.SSN
         select new NeshtoSi { ssn = d.SSN, name = p.Name, surname = p.Surname };


IQueryable<NeshtoSi> sQuery = dd;

if (!string.IsNullOrEmpty(serName.Text))
    sQuery = sQuery.Where(x => x.name.Contains(serName.Text));
if (!string.IsNullOrEmpty(serSurame.Text))
    sQuery = sQuery.Where(x => x.surname.Contains(serSurame.Text));
if (!string.IsNullOrEmpty(serSSN.Text))
    sQuery = sQuery.Where(x => x.ssn.Contains(serSSN.Text));

var results = sQuery.ToList();

AnSearch.ItemsSource = sQuery;

I hope that someone can help me...

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Branimir
  • 53
  • 2
  • 10

2 Answers2

2

The code that you presented seems ok - it doesn't matter how an object is created - what matters is the object itself.

Rather than showing us this, you should show the xaml.

One more thing - are we talking about DataGridView from winforms or rather the one that comes with WPF Toolkit ?

=======================================

Sorry. I've missed it in the first place - you don't have properties in your class! You've created public fields instead of properties and that's probably the problem.

The code should look like this:

 public class NeshtoSi
{
    public NeshtoSi() { }

    public string ssn{get; set;}
    public string name{get; set;}
    public string surname{get; set;}
}
kubal5003
  • 7,186
  • 8
  • 52
  • 90
  • BTW, is there a way to bind these to the text columns in order to display different(Descriptive) headers? I tried – Branimir Dec 08 '09 at 00:07
0

I went through this recently, and the answer is outlined in a post of mine that is here

Community
  • 1
  • 1
Berryl
  • 12,471
  • 22
  • 98
  • 182