Click here to Skip to main content
15,881,413 members
Home / Discussions / C#
   

C#

 
AnswerRe: hello friend :) Pin
fjdiewornncalwe11-Dec-12 10:34
professionalfjdiewornncalwe11-Dec-12 10:34 
AnswerRe: hello friend :) Pin
Pete O'Hanlon11-Dec-12 8:22
mvePete O'Hanlon11-Dec-12 8:22 
GeneralRe: hello friend :) Pin
youshy11-Dec-12 9:12
youshy11-Dec-12 9:12 
GeneralMessage Removed Pin
12-Dec-12 2:50
professionalN_tro_P12-Dec-12 2:50 
GeneralRe: hello friend :) Pin
Pete O'Hanlon12-Dec-12 2:53
mvePete O'Hanlon12-Dec-12 2:53 
QuestionBest way to do this? Pin
SledgeHammer0111-Dec-12 4:55
SledgeHammer0111-Dec-12 4:55 
AnswerRe: Best way to do this? Pin
Gerry Schmitz11-Dec-12 12:28
mveGerry Schmitz11-Dec-12 12:28 
GeneralRe: Best way to do this? Pin
SledgeHammer0111-Dec-12 13:21
SledgeHammer0111-Dec-12 13:21 
I was trying to avoid having 2 collections and "sync'ing" them up. I'm probably not going to have that many items, but purposely storing multiple copies of the same object is not something I want to do. In regards to step #2 and #3, I'm going to be using data binding, so it all really needs to be the same instance of all the objects. I came up with something that sort of works, but I'm not happy with it:

C#
public class HybridCollection : ObservableDictionary<ObjType, ObservableCollection<Obj>>
{
    public HybridCollection()
        : base()
    {
    }

    public void Add(Obj o)
    {
        ObservableCollection<Obj> lst = null;

        if (!this.TryGetValue(o.Type, out lst))
        {
            lst = new ObservableCollection<Obj>();
            this[o.Type] = lst;
        }

        lst.Add(o);

        cv.Refresh();
    }

    public IEnumerable<Obj> FlatView
    {
        get
        {
            foreach (ObservableCollection<Obj> lst in Values)
            {
                foreach (Obj obj in lst)
                    yield return obj;
            }
        }
    }

    private CollectionView cv = null;

    public CollectionView FlatView2
    {
        get
        {
            if (cv == null)
                cv = new CollectionView(FlatView);

            return cv;
        }
    }
}


So what happens is, the data is stored hierachially so the treeview can bind to it with the HierachialDataTemplates. FlatView2 just returns an IEnumerable where it enums through all the branches and yields the original objects back.

Unfortunately, in the Add() method (and of course the delete, etc methods), there is a cv.Refresh() call to refresh the flat view since the IEnumerable isn't going to be able to propogate change notifications. So the treeview is going to use optimized data binding where it adds / removes only the affected items, but the listview will be reloading the entire list. Ugh.

I guess I will have to return an ObservableCollection instead of the IEnumerable... was kind of hoping to prevent that.
GeneralRe: Best way to do this? Pin
Gerry Schmitz11-Dec-12 14:05
mveGerry Schmitz11-Dec-12 14:05 
GeneralRe: Best way to do this? Pin
SledgeHammer0111-Dec-12 14:25
SledgeHammer0111-Dec-12 14:25 
Questiondevelop code project functionality(view forums/questions) in codeproject like steps View Pin
Firoz(Pappu)11-Dec-12 3:40
Firoz(Pappu)11-Dec-12 3:40 
AnswerRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Richard MacCutchan11-Dec-12 5:00
mveRichard MacCutchan11-Dec-12 5:00 
GeneralRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Firoz(Pappu)11-Dec-12 5:37
Firoz(Pappu)11-Dec-12 5:37 
GeneralRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Pete O'Hanlon11-Dec-12 6:01
mvePete O'Hanlon11-Dec-12 6:01 
GeneralRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Firoz(Pappu)11-Dec-12 20:30
Firoz(Pappu)11-Dec-12 20:30 
GeneralRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Pete O'Hanlon11-Dec-12 20:37
mvePete O'Hanlon11-Dec-12 20:37 
AnswerRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Jay Nardev12-Dec-12 21:43
Jay Nardev12-Dec-12 21:43 
GeneralRe: develop code project functionality(view forums/questions) in codeproject like steps View Pin
Firoz(Pappu)12-Dec-12 22:17
Firoz(Pappu)12-Dec-12 22:17 
QuestionC# javascript communication Pin
tashee11-Dec-12 2:12
tashee11-Dec-12 2:12 
AnswerRe: C# javascript communication Pin
V.11-Dec-12 3:40
professionalV.11-Dec-12 3:40 
QuestionWCF Services in a multi threaded application results in Oracle Connection request Timed out error Pin
rajaron11-Dec-12 0:16
rajaron11-Dec-12 0:16 
Questionimage from access database in c# Pin
kojoam110-Dec-12 4:10
kojoam110-Dec-12 4:10 
QuestionRe: image from access database in c# Pin
Richard MacCutchan10-Dec-12 21:29
mveRichard MacCutchan10-Dec-12 21:29 
AnswerRe: image from access database in c# Pin
Pete O'Hanlon10-Dec-12 22:15
mvePete O'Hanlon10-Dec-12 22:15 
GeneralRe: image from access database in c# Pin
Richard MacCutchan10-Dec-12 22:40
mveRichard MacCutchan10-Dec-12 22:40 

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.