|
Really simplified, I have this object:
enum ObjectType
{
Type1,
Type2
}
class SomeClass
{
string someProp;
ObjectType type;
}
Specs call for the right pane to be a flat list in a list control of ALL SomeClass objects. Left pane will be a treeview grouped by ObjectType. I.e.
ObjectType1
SomeObject1
SomeObject2
SomeObject3
ObjectType2
SomeObject4
SomeObject5
Obviously, if the user changes the type of SomeObject5 from ObjectType2 to ObjectType1, the tree on the left should re-arrange itself appropriately.
This app is WPF / MVVM, so keep that in mind.
I know I can do some ghetto hack where the VM for the right pane just grabs its own copy of the hierachial list and flattens it and displays that while the left pane just displays the hierachial list. Or vice versa. List is stored as a flat list and the left pane builds a hierachial collection.
Not liking either of those ideas because in the WPF world, you really need to be operating on the same exact instance of an object so change notification works.
I guess what I'm thinking is some kind of hierachial structure that also has a "FlatView" and operating on the hierachial methods will auto sync the flat view and vice versa. Basically, I'd like the left pane and the right pane to operate on the same exact collection and the same exact objects, but just display them differently.
|
|
|
|
|
Conceptually:
1) Create an Observable.Collection that contains the "original" objects
2) Load the "Tree View" with "references" to objects in (1)
3) Load the "List View" with "references" to objects in (1)
4) Subscribe to the OnCollectionChanged event of (1) so that when an object is added, removed, etc to/from (1), the event handler "syncs" the Tree and List views by adding, removing, etc. items from those views.
5) Wire up the UI so that an "Add", etc. to the Tree or List View actually operates on (1) using an item object reference from (2) or (3).
|
|
|
|
|
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:
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.
|
|
|
|
|
I tried to emphasize that Collection (1) had the "original" objects; i.e. the first and only "instances".
The item sources for views (2) and (3) contain "references" to the objects in (1); so, there is no "duplication" of objects; e.g.
object o1 = new object();
object o2 = o1;
object o3 = o1;
As illustrated above, there is only one object "instance"; 02 and 03 are "references" to the original object (much as I'm suggesting the way the views should operate); with collection (1) driving the changes to the views' items collections via OnCollectionChanged.
If you are saying, you don't want to maintain "additional references" that is another matter; but that is not the same as "copying" (i.e. "cloning") objects.
(And anytime there is a List control bound to any collection, there is an implicit loading of "references" into the control from the data source).
In any event, due to the hierarchical nature of the Tree View versus a "flat" list it is pretty hard to come up with a "single" data source that can handle both at the same time.
|
|
|
|
|
Yeah, I understand. The code in my previous response "works" and is "a single collection" IMO since its just a matter of enumerating through in a specific way (FlatView). The only problem as I mentioned was that the FlatView didn't put out collection change notifications. I gave up and changed FlatView to an ObservableCollection and now the collection changes work. I guess I was imagining something magical like CollectionView / CollectionViewSource where its a "view" of the collection in a different way without building a second collection. Guess you can't do something like that.
|
|
|
|
|
I am new to ASP.Net Please.
i want to develop question answer view in codeproject forum like (accordion like onclick Expand details and again collapse)in step like.
Regards,
Pappu
|
|
|
|
|
Firoz(Pappu) wrote: I am new to ASP.Net Then your question would be better in the ASP.NET forum[^].
Firoz(Pappu) wrote: i want to develop Fine, but if you want help you need to give a bit more detail about your actual problem.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks For Reply,
same view like view question posted and reply's and showing tree like structure, on click expanding details of question/reply's. in codeproject forum.
regards,
Firoz
|
|
|
|
|
That's not a question either. That's a vague statement of a requirement that looks like you hope someone will give you code.
|
|
|
|
|
Hi,
please see link forum view which contains onclick it expands and other will collapse and if click on other one will expand and expanded question/reply will collapse same like view.
for example.
question
Re: Reply1
Re: Re:Reply For Rely
|
|
|
|
|
But what code do you already have in place? And as a hint - CodeProject expands things at the client side, so it uses JavaScript not C# to do this.
|
|
|
|
|
Please check below link.
<a href="http://api.jquery.com/toggle/">http://api.jquery.com/toggle/</a>[<a href="http://api.jquery.com/toggle/" target="_blank" title="New Window">^</a>]
This will help you to implement at client side.
|
|
|
|
|
|
hello,
I am creating a data visualization tool using C# and Javascript. I have embedded a webbrowser control in a C# winform application and have written a javascript code for it.
My problem is i need to pass a value from javascript to C#. I am successfully able to pass value from C# to Javascript but not vice-versa.
my javascript code is
google.maps.event.addListener(marker, 'dragend', function(ev){
var newpos= marker.getPosition();
});
i want to pass value of newpos to C# so that i can use it for further computation
please help me for this.
|
|
|
|
|
yes, it can be a bitch. What you can do is add a server control (label, textbox, ...) and hide it. You can assign a clientid to that control. That client id is known by javascript. In fact, you can just assign it a server id and load the page. If you search the control in your webpage source you'll find that .net created a client id for you (mostly the server id with an autogenerated suffix like c001 or something).
hope this helps.
|
|
|
|
|
I am using WCF services with Thread Pool concepts in the application using Oracle Database. The application has a Scheduling Workflow, where there will be multiple Jobs scheduled at the same time. The expected behavior is that, once the scheduler is triggered, all the jobs should be started parallel and at the background, various process are run.
All the jobs are not started in parallel. Say for example, if there are 20 jobs scheduled, only 15 are getting started and remaining are struck.
It results in Oracle Connection request timed out error.
Options Tried:
As the application uses PerSession and Concurrency mode as Multiple. Tried this could have been a WCF Throttling issues. So modified the Throttling parameters as well. But still results in Oracle error.
Any help would be appreciated.
|
|
|
|
|
pls help wiht this code
int intOrder = int.Parse(frmInput.InvoiceOrder);
byte[] photo_aray;
OleDbDataAdapter adapter = new OleDbDataAdapter("select photo from cards where id= " + intOrder, strCon);
DataSet ds = new DataSet();
adapter.Fill(ds, "cards");
// ds.Tables[0].Constraints.Add("pk_sno", ds.Tables[0].Columns[0], true);
picBox1.Image = null;
if (ds.Tables[0].Rows[rno][6] != System.DBNull.Value)
{
photo_aray = (byte[])ds.Tables[0].Rows[rno][6];
MemoryStream ms = new MemoryStream(photo_aray);
picBox1.Image = Image.FromStream(ms);
}
}
image not showing in picbox
|
|
|
|
|
Have you used your debugger to step through this code and check that all your variables are correctly loaded with the information that you have in the database, and that the picturebox image is a real image?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard MacCutchan wrote: Have you used your debugger
Oh you and your hilarious one liners.
|
|
|
|
|
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard's right. Add a breakpoint on the if statement. To do this, you can click on the line and press F9 (this is the shortcut to toggle the breakpoint on and off). You should see a red dot appear in the gutter in Visual Studio. Press F5 to run your application. When you hit the if statement, press F10 to step over the code. If you do this you will find out if this value is null or not.
Now, one thing I would do is wrap the MemoryStream in a using statement. A MemoryStream is a disposable object, so you should always dispose of it. This would give you:
using (MemoryStream ms = new MemoryStream(photo_array))
{
picBox1.Image = Image.FromStream(ms);
} Your code will now dispose of the stream.
|
|
|
|
|
Hi
I want to load a bitmap do some changes on the pixels and save it as new bitmap with a new name.
Will it work if I'll use the save method of the bitmap class (I'll give it as a parameter the path with the name "C:\\NewBitmap.bmp" for example, or is there another method for doing it?
thanks.
|
|
|
|
|
gibsray wrote: Will it work if I'll use the save method of the bitmap class
I can't see why not.
|
|
|
|
|
Yes - the Save method is the one to use.
Two things to note though:
1) Don't try to save it to the root directory - Vista and above won't let you write to the root of the boot drive to help prevent virus and trojan attacks - use a different directory unless you app has admin privileges.
2) Be careful what format you save the image in: many types including JPG are lossy compression, so each time you save and open it you will get a fuzzier, less detailed image. Use BMP or similar for working images, and JPG for final presentation only.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
I can not icon & background in form design ....
Half Blood
|
|
|
|