views:

283

answers:

3

Hello,

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...

+2  A: 

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
Thank you very much!!! This solved the problem!
Branimir
BTW, is there a way to bind these to the text columns in order to display different(Descriptive) headers? I tried <toolkit:DataGridTextColumn x:Name="column1" Header="SSN" Binding="{Binding ssn }" />
Branimir
A: 

Do you refresh the datagrid?

Partial
A: 

Branimir

RE: Header binding

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

HTH,
Berryl

Berryl