I am working with a treeview in WPF
I have two classes that I am using to populate two levels of a treeview.
The first question is can I do this with one query or any better than I have achieved with below.
The main question is that I want to include the h.ItemId and other columns from the ViewDocItems and still achieve the hierarchy in the treeview.
Right now the Title from DocHistory class is the root level of the tree.
And BaseNumber from BaseHistory is the second level.
public class DocHistory
{
private ObservableCollection<BaseHistory> mBaseHis = new ObservableCollection<BaseHistory>();
public Guid Id { get; set; }
public Guid ClassId { get; set; }
public string Title { get; set; }
public ObservableCollection<BaseHistory> BaseHis { get { return mBaseline; } }
}
public class BaseHistory
{
public Guid BaseId { get; set; }
public string BaseName { get; set; }
public int BaseNumber { get; set; }
public bool BaseFinal { get; set; }
}
//this guid is only for testing
mGuid = new Guid("0497F3DA-AE3E-40C7-AF91-9B26EEE2A437");
var query = (from d in mContext.Docs
orderby d.Title ascending
join b in mContext.Base on d.DocId equals b.DocId
join h in mContext.ViewDocItems on b.BaseId equals h.BaseId
where h.ItemId == mGuid
select d).Distinct();
List<Database.Doc> DocList = query.ToList();
foreach (Database.Doc result in DocList)
{
DocHistory newHistory = new DocuHistory() { Id = result.DocId, Title = result.Title, ClassId = result.ClassId };
mHistory.Add(newHistory);
var documents = from d in result.Base
orderby d.LineNumber
select new BaseHistory()
{
BaseId = d.BaseId,
Name = d.Title,
BaseFinal = d.Final.Value,
LineNumber = d.LineNumber.Value
};
documents.ToList().ForEach(d => newHistory.BaseHis.Add(d));
}
Here is the property I am binding to
private ObservableCollection<DocHistory> mHistory = new ObservableCollection<DocHistory>();
public ObservableCollection<DocHistory> DocsHistory
{
get
{
return mHistory;
}
}
I am using ItemsSource="{Binding Path=DocsHistory}" for the treeView
And The Hierarchial DataTemplate is Binding to BaseHis