views:

13

answers:

1

Hi, i have a class Auswahl with some plain properties and a property RefFilters of type

List<RefAuswahlFilter>

What i want to achieve is: Display all Auswahl Properties in a datagrid with all RefFilter items in ONE row. the Problem is, the count of RefFilter is different from auswahl to auswahl object. in the past i use a datatable as the collection source. there i just added the MAX reffilters count as columns.

now i want to achieve this without a datatable, with something like "dynamic" Properties or anything.

public class Auswahl
{
    public Auswahl()
    {
        this.RefFilters = new List<RefAuswahlFilter>();
    }

    public virtual string Beschreibung {get; set; }
    public virtual long Id { get; set; }
    public virtual string Programm { get; set; }
    public virtual string Returnkey { get; set; }
    public virtual string Variante { get; set; }

    //RefFilters contains a Rank and a Filter Property
    public virtual IList<RefAuswahlFilter> RefFilters { get; set; }


 public class AuswahlVM
 {
    ...
    public ObservableCollection<Auswahl> Auswahlliste { get; private set; }

    public void FillList()
    {

            try
            {
                var l = session.CreateCriteria(typeof(Auswahl)).List<Auswahl>().Where(x =>!String.IsNullOrEmpty(x.Returnkey));
                this.Auswahlliste = new ObservableCollection<Auswahl>(l);
            }
            catch (Exception ex)
            {

            }

    }
A: 

well i ended up in creating a helper class with an indexer and map my original list in that helper class

public class RefAuswahlFilterListe
{
    private IList<RefAuswahlFilter> refFilters;
    private Auswahl auswahl;
    public RefAuswahlFilterListe(Auswahl refauswahl, IList<RefAuswahlFilter> filter)
    {
        this.refFilters = filter;
        this.auswahl = refauswahl;
    }

    public string this[string rank]
    {
        get
        {
            long index;
            if(Int64.TryParse(rank, out index))
            {
                var result = this.refFilters.FirstOrDefault(x => x.Filterrank == index);
                return result != null ? result.Filter : String.Empty;
            }
            return String.Empty;
        }
        set
        {
            long index;
            if (Int64.TryParse(rank, out index))
            {
                var result = this.refFilters.FirstOrDefault(x => x.Filterrank == index);

                if(result == null)
                    this.refFilters.Add(new RefAuswahlFilter(){Auswahl = auswahl,Filter = value, Filterrank = index});
                else
                    result.Filter = value;
            }

        }
    }

}

<DataGridTextColumn Header="Filter1" 
                    ToolTipService.ToolTip="Filter Spalte"
                    Binding="{Binding Path=Filter[1]}">
</DataGridTextColumn>
<DataGridTextColumn Header="Filter2" 
                    ToolTipService.ToolTip="Filter Spalte"
                    Binding="{Binding Path=Filter[2]}"/>

i really dont know if this is the way to go. and i still has the problem to create wpf DataGridTextColumns dynamic (maybe in code behind?) cause it must be at least so much Columns like the highest count of RefFilters.

blindmeis