|
Or SortedList. Ex:
public SortedList<Animal, Zoo> map = new SortedList<Animal, Zoo>();
...
...
...
zoo.animals = (from animal in animalList
where map[animal].Id == zoo.Id
select animal).ToList();
}
or
public SortedList<int, int> map = new SortedList<int, int>();
...
...
...
zoo.animals = (from animal in animalList
where map[animal.Id] == zoo.Id
select animal).ToList(); modified on Wednesday, March 10, 2010 2:25 PM
|
|
|
|
|
Thanks!
SortedList is what I was looking for.
|
|
|
|
|
Your 3rd collection is necessary, in fact it breaks the object encapsulation IMO.
What you really need is a List<Zoo> property on Animal , and conversely a List<Animal> property on Zoo . All you need do is ensure that the lists are not accessible publicly, and methods are provided for addition / removal to both list properties "simultaneously" (i.e. adding an Animal to a zoo also adds that zoo to an animal). You will also need properties or methods for getting copies (so the originals are unalterable externally) of the lists.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Or make them totally unaware of each other as in:
class Animal{
public int Id{get;set;}
public string Name{get;set;}
}
class Zoo{
public int Id{get;set;}
public string Name{get;set;}
}
SortedList<int,int> animalZooJonction = new SortedList<int, int>();
var animalsInSpecifiedZoo = (from rec in animals
where animalZooJonction[rec.Id] == zoo
select rec).ToList();
While it is not as keen on respecting standars it is faster and it does consume less memory.
|
|
|
|
|
Thanks for the reply.
I have tried to make actual scenario simpler with that example. The actual code is a bit different. What you have said is there in the actual code as well except for having lists in both the classes.
|
|
|
|
|
I need to run an installer action under the current user context, while it is runned under System user's context.
How it is possible?
|
|
|
|
|
|
0) PDFWriter there only supplies an emulated printer in your printer list that will create your PDFs for you so doesn't have any programmatic interface for you to use.
1) You need to instead go for their SDK here: http://www.cutepdf.com/Solutions/FormSDK.asp[^]
2) If you hit snags with that, I suggest you use cutepdf's support options. CP is more about generic programming techniques, not software specific ones that belong to people unaffiliated with it.
|
|
|
|
|
Hi All!
I’ve made a class that inherits from ComboBox and have added MinDate, MaxDate, and Value properties. In the constructor of the class I set the default values I want for those properties (they can be overridden by setting the property).
I used the VS 2005 designer to place my custom ComboBoxes on my form, but the designer keeps assigning default values for MinDate, MaxDate, and Value which are overriding the defaults I set in the constructor. When I try and remove the designer code that just deals with the assignment of those three properties the designer adds them back in after the next edit.
Is there a way to still use the designer but not have it hijack my custom controls?
Thank you all in advance!
|
|
|
|
|
On your properties you need to have the DefaultValue attribute with your defaults in. This will then stop the designer automatically overriding your defaults. This will also give you Reset functionality in the designer.
E.g.
[System.ComponentModel.DefaultValue("My Default value")]
public string MyProperty{
set{
}
}
|
|
|
|
|
Thank you for the reply. This looks like what I’m looking for. However, the complier won’t let me set the DefaultValue to DateTime.Now (or any other DateTime object) and I’ve had no luck finding an answer on the net.
The complier complains with the error “An attribute argument must be a constant expression, typeof expression or array creation expression”
It seems like the Designer is setting all of these values because it wants to be able to display how my control would actually look when run, but I don’t care about that at design time, I’m just using the designer to line up my controls.
Is there a way to stop the designer from trying to “figure out” what my control would look like and just set its placement?
Thanks again!
|
|
|
|
|
Anticast wrote: However, the complier won’t let me set the DefaultValue to DateTime.Now (or any other DateTime object) and I’ve had no luck finding an answer on the net.
In orther to use it as default value, use this: [DefaultValue(typeof(DateTime), "Now")]
NOTE: When using atribute DefaultValue, you must also set the default value to the code. this attribute only tells to your IDE. And IDE (VS08 or others) removes property from auto generated code. DateTime changes and it is impossible to use it as default value without Type converzion. Introduction to the TypeConverter
Anticast wrote: Is there a way to stop the designer from trying to “figure out” what my control would look like and just set its placement?
I do not understand you with this. Are you looking into this.DesignMode property in order to change behaviour?. Designer can't try to figure out your controls look. Every time you compile IDE uses its compiled info and then it displays on designer by using latest build
|
|
|
|
|
If you don't want the designer to serialize your properties, add a System.ComponentModel.DesignerSerializationVisibilityAttribute set to NeverDave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Awesome! This did exactly what I was looking for. Thank you!
For anyone else that is using ComboBoxes (or similar controls, I'm sure) I also had to add:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
new public ComboBox.ObjectCollection Items
{
get
{
return base.Items;
}
}
to get the Designer to stop adding items to my collection. Without this the constructor was adding its items, then the designer added those items again.
Thanks again!
|
|
|
|
|
HI All,
I need to implement chroma key features.
I need to draw a graphics on a pictures box and apply to this a chroma key at background color (es Violet) to see a playback video that is under this control.
I must see a graphics and a playback video at the same time.
Can you help me with example?
Thanks.Alex
|
|
|
|
|
Hi,
Is there any way to find out if a SqlConnection has an open SqlTransaction?
Basically I have an object with a method that accepts a SqlConnection as a parameter. This method is called from a number of different application. Sometimes the SqlConnection has a SqlTransaction and other times it doesn't.
So what I need to be able to do is something along the lines of
public bool Post(SqlConnection cn, int ID)
{
SqlTransaction trans;
if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}
return true;
}
Is there anyway to get something similar?
Thanks,
David
|
|
|
|
|
I rather suspect that you could just check to see if the Transaction is null or not on the command."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
There is no command being passed in, just a connection.
So when I create a command object I want to do something like.
SqlTransaction trans = null;
cmd.Connection = cn;
if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}
cmd.Transaction = trans;
|
|
|
|
|
Shouldn't you track that yourself?
|
|
|
|
|
Ideally we would/should be.
But there are so many applications using this class at the moment that it's not really feasible to revisit them all right now.
|
|
|
|
|
I'm looking to add webcam support to a web page but i really have no idea where to start. I can use any version of VS so thats not a problem. I've seen a few examples on here about how to do it but they were all over the place. Any ideas on where to start? I'm obviously not ask for code to do it but whats the easiest way to get it done would be helpful. Thank you in advance.
|
|
|
|
|
Hi...
If you have seen the Gmail webcam support from browser while chatting, the same can be implemented.
To enable webcam support Gmail asks to download an activeX at first. So you also can create and API in C# which will capture the image from the webcam and ask the user to download it when he/she wants to have webcam support.
You API will search for the webcam on various ports of the users computer and streams images from webcam to your server and also display it to the user in a window.
I hope this approach will give some idea and lead to your goal.
Thanks and regards,
Chetan RanpariyaThanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hi,
I am a beginner to create Facebook application. Will appreciate if someone can explain how to get and use offline access session key?
regards,
rnv
|
|
|
|
|
Have you checked out the Facebook developers community[^]?
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
Hi. I've recently had to do this as well. I used the following:
browserFacebook.Navigate(@"http://www.facebook.com/login.php?api_key=" + FacebookAPIKey + @"&connect_display=popup&v=1.0&
next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&
fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access");
You can intercept this URL once its done loading (string s = browserFacebook.Url.ToString() ) which will show you the session key thats been returned
|
|
|
|