|
It depends what you want to do. If you are just setting a variable or two based on the result, I'd build a hashtable of type to return value, and set it in one line.
Either way, I'd always use a switch over massive if/else blocks.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Basically I am enumerating all of the network adapters on the system and then allowing the user to specify which type to view (only the type selected are shown). It is really only used once.
Matt Newman
Even the very best tools in the hands of an idiot will produce something of little or no value. - Chris Meech on Idiots
|
|
|
|
|
I reckon the trick is to make the value associated with the strings in the drop down equal the enum value, if that's all you need. Or, better yet, use Enum.Parse to make an enum value out of the string, and use Enum.(whatever the method is that returns a string array from an enum ) to populate it.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Keep in mind that InterfaceType has a backing value type of Int32. My experience with Windows Forms is limited, but if you could get an index value of some type from the combobox, you could cast that value to a variable of type InterfaceType.
i.e.:
InterfaceType selectedType = (InterfaceType) val;
(where val is the index number pulled in through the combobox)
Then you'd only have one conditional statement checking for equality:
if (interfaces[i].Type == selectedType)
Hope this helps!
~ Levi
|
|
|
|
|
Good idea... but this is the index list (of all InterfaceTypes)
94 AsymmetricDsl
37 Atm
20 BasicIsdn
6 Ethernet
26 Ethernet3MegaBit
69 FastEthernetFx
62 FastEthernetT
15 Fddi
48 GenericModem
117 GigaBitEthernet
144 HighPerformanceSerialBus
114 IPOverAtm
63 Isdn
24 Loopback
143 MultiRateSymmetricDsl
23 Ppp
21 PrimaryIsdn
95 RateAdaptDsl
28 Slip
96 SymmetricDsl
9 TokenRing
131 Tunnel
1 Unknown
97 VeryHighSpeedDsl
71 Wireless80211
So I cant just do 0 -> 0 1->1 etc
Matt Newman
Even the very best tools in the hands of an idiot will produce something of little or no value. - Chris Meech on Idiots
|
|
|
|
|
From what I understand about Combobox controls in .NET:
- The Add() method accepts an object as a parameter, and the object's ToString() return value is what actually gets displayed in the Combobox.
- The SelectedItem property returns the object (not the ToString() result) that is selected.
Perhaps it would be possible to create a new struct containing an InterfaceType field, a string field, and a simple ToString() method to make this work. When you use the SelectedItem property of the Combobox to return the currently selected object, you could simply read back its InterfaceType field.
Like I said, I've not used Windows Forms since VB6, so hopefully somebody will correct me if I am in error.
Good luck!
~ Levi
|
|
|
|
|
|
hello,
i have a dynamic control that i add the control collection.
this control is being loaded from ascx.
if i want to change, while postback, the ascx i load, i retrieve a message that i can't since
so what i want to do is to be able to delete control viewstate while postback.
can i do so?
many thanks,
Eran.
|
|
|
|
|
Your question belongs in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
I have an imagelist, created in the IDE, and it generated this code for me :
this.imageList.ImageSize = new System.Drawing.Size(23, 23);
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Lime;
the second line generates this error:
+ System.SystemException {"Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure \"DetailsActions.resources\" was correctly embedded or linked into assembly \"RDC\".\r\nbaseName: DetailsActions locationInfo: RDC.DetailsActions resource file name: DetailsActions.resources assembly: RDC, Version=1.0.1035.19142, Culture=neutral, PublicKeyToken=null"} System.SystemException
Now, I don't see any way to make the images or the image list build into the assembly, but I don't think that's the problem. I've found some stuff on google, but nothing that's been suggested has helped.
The resourceSets property on the resource object is 0. That is created like this :
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailsActions));
The details actions class is in a subfolder called controls, I've tried adding controls to the path. This project was actually in VB.NET, I just converted it using a tool, but the VB.NET code looks the same to me, and it works.
My default namespace for the project is RDC, the root namespace of the project. Any suggestions anyone can offer are truly appreciated.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
The DetailsActions.resources - generated from DetailsActions.resx - was not embedded into the assembly. You won't see this by default in the IDE, so you'll need to go to Project->Show Hidden Files to see it. It should be nested under the form or control to which it's related. The images or image strip that you assigm to an ImageList is base64-encoded into a ResX file, which gets generated into a .resources file and embedded.
If you want to forego the ResX file, then add the images or image list to your project and set the Build Action to Embedded Resource. To create the image or images to add to the ImageList , use something like the following:
Image img;
using (Stream s = GetType().Assembly.GetManifestResourceStream("NameSpace.ImageStrip.png"))
img = Image.FromStream(s); Make sure that "NameSpace" is the fully-qualified namespace of the object you added. So, if your project's default namespace is "RDC" and your image was called "ImageStrip.png" under a folder named "Example", then the fully-qualified manifest resource name is "RDC.Example.ImageStrip.png". Any embedded resources - even .resources files - use this convention unless you explicitly embedded the resources into the assembly (i.e., not using VS.NET or re-assemblying the assembly).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
OK, I can see the resx file now, and it's an embedded resource, so it must be in there.
I've inherited this project, the only form in which I have the bitmaps is this project file, where they are embedded in the imageList, with the obvious exception that I cannot get them out. How do I go about turning the list into a collection of bitmaps so I can load them into an image list manually ? Or, preferably, how can I make this code work as it stands ?
If I look at the XML, I can see the image stream there. I've tried all sorts of variations in the path I pass in to the resource object. Is there a way I can query it to find out the path I need ?
Thanks for your help.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
The resources object is created like this:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("DetailsActions", System.Reflection.Assembly.GetExecutingAssembly());
I tried controls.DetailsActions ( because it's in a folder called 'controls' ) to no avail. I've tried various other permutations, and I've also established that all my other image lists ( that reside in the root folder ) are loading fine. I've also reverified that the existing code works perfectly in the VB.NET version. I have no idea what to do next...
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
The ResourceManager should - if the file "path" in the manifest is the same as the fully-qualified class name - use new ResourceManager(typeof(DetailsActions)) .
Make sure the .resources file is in there. Open the assembly in ildasm.exe (installed by the Framework SDK, which is installed with VS.NET by default, into the SDK's Bin directory), double-click "MANIFEST", and search for "RDC.controls.DetailsActions.resources" below the assembly attributes.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I found this:
.mresource public RDC.controls.DetailsActions.resources
{
}
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Then in your DetailsActions.cs (assuming similar class and filename) do this:
new ResourceManager(typeof(DetailsActions)) The ResourceManager uses the Type namespace and class name and appends ".resources" to get the resource. If you were to specify the resource yourself, you would have to do:
new ResourceManager("RDC.controls.DetailsActions.resources", Assembly.GetExecutingAssembly()); Though the example isn't right, you might - for sanity's sake - look in the ResX file to make sure a data name with "imageList1.Images" (or whatever the key is) exists in the file.
Any class defaults to using the project's root namespace (configured in the project) + any folders. This is for C#. VB.NET, on the other hand, builds the namespace up for each folder and is not cummulative. Make sure your class files don't repeat namespace parts for folder that already exist.
Resources, in both cases, are handled like classes in VB.NET: the "namespace" is built from the project root namespace + any folders down the line to the file to embed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Though the example isn't right, you might - for sanity's sake - look in the ResX file to make sure a data name with "imageList1.Images" (or whatever the key is) exists in the file.
Did that - it's there. It's .ImageStream, I believe, either way, it's the same thing the code that blows up is looking for.
Heath Stewart wrote:
new ResourceManager(typeof(DetailsActions))
Sorry, it did that originally, and I've changed it back. I should have said when you mentioned it before.
I really appreciate your help with this.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Make sure your source file in VB.NET doesn't include the full namespace, like:
Namespace RDC
Namespace controls
Public Class DetailsActions
' ...
End Class
End Namespace
End Namespace What will happen, if the project's root namespace is "RDC" already, and this in a folder calls "controls", is that you'll have a fully-qualified class as RDC.controls.RDC.controls.DetailsActions .
If you're using the other overload for ResourceManager to specify the name, specify exactly the name you saw in the assembly manifest when using ildasm.exe, including the extension.
I feel so dirty writing VB.NET code in the C# forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
In VB.NET, it doesn't include a namespace at all. Could this be the problem ?
Heath Stewart wrote:
If you're using the other overload for ResourceManager to specify the name, specify exactly the name you saw in the assembly manifest when using ildasm.exe, including the extension.
I'm using the typeof one again now, because that's what it was originally, I was just looking for a way to specify the namespace, but it didn't help.
Heath Stewart wrote:
I feel so dirty writing VB.NET code in the C# forum
*grin* what's happening here is that we're being paid to work on some code that was in VB, and we refused unless we could convert it to C#. We did this, using a conversion tool, and the authors of the tool can't tell us why this is happening, although it has something to do with the subfolder, all the other image lists are not in subfolders, and work fine.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
In VB.NET, it doesn't include a namespace at all. Could this be the problem ?
It shouldn't. Whatever namespace is specified in the source file is appended to the namespace built up by the root project namespace plus any folders. At least that's what I remember from my stint with VB.NET 1.0 years ago.
Use ildasm.exe to view the type metadata. I'm sure you're answer lies there.
Christian Graus wrote:
I'm using the typeof one again now, because that's what it was originally, I was just looking for a way to specify the namespace, but it didn't help.
Once you get everything figured out, this is best. This allows you to move the source file and ResX file around in VB.NET. That's one nice thing. In C# you'd have to mind your namespace in the source file.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
OK, well all it tells me is what I know - the full 'path' is RDC.controls.imageList.ImageCollection. I know that the .controls bit is what's making the problem, but I do not know what to do about it. I'm going to read Pezold about it tonight and see if he says anything. His windows forms book is full of info on GDI+, but very thin on what controls he actually even uses, so it's a mixed bag.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
The namespace is RDC.controls , but what are you referring to as a "path"? I can help you (I've dealt more with localization of managed application than most people I know), but I need to understand what you're looking at exactly.
The source file will have a namespace, but in VB.NET - unlike in C# - you don't specify the entire namespace (if any) in the source file. If you use ResourceManager and pass it a Type to the constructor, then the namespace of the embedded resource and the namespace of the class must be the same, as do the class names. The embedded resource simply adds .resources to get the resources file.
So, if the fully-qualified class name is RDC.controls.imageList.ImageCollection - which doesn't make any sense from what you've told me already - then the .resources file should be embedded as RDC.controls.imageList.ImageCollection.resources.
The VB.NET project treats source files and embedded resources the same. It builds up their namespaces using the project root namespace + any folders up to the file.
Yesterday you told me that the class was RDC.controls.DetailsActions . When you say "path", are you talking about the data name in the ResX file? The name in the ResX file should match the name that you get using ResourceManager.GetObject .
If you specify a "path" (fully-qualified manifest resource name) for ResourceManager than it must include the entire "path": RDC.controls.DetailsActions.resources.
If you can, why not post some sample source and the structure of your project. And define what you mean by "path" and to what that "path" refers.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Stop the presses !!!
Thanks for all your help - I tried loading the resourcemanager with this:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly());
and it works fine. I'm at a loss though, I'm sure this is what I tried yesterday....
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Have you checked the 'DefaultNamespace' property of your project? The namespace in which a .resx file is placed is determined by studio to be:
[DefaultProjectNamespace].([Folder].[Folder].etc).ResourceFileName
If this production does not match exactly the declared namespace for your class, the ResourceManager won't be able to find the resources for the class. This has happenned to me on numerous occasions after moving around classes in a project that has a non-standard DefaultProjectNamespace (e.g. it's not just 'AssemblyName').
--
Russell Morris
"So, broccoli, mother says you're good for me... but I'm afraid I'm no good for you!" - Stewy
|
|
|
|
|