|
Since you appear to have the code to read from a file, all you need to do is list the relevant files into a list box - which is pretty much trivial to do:
private void LoadFileNames(string folder, string extension, ListBox lb)
{
string[] files = Directory.GetFiles(folder, "*" + extension);
lb.DataSource = files.Select(f => Path.GetFileNameWithoutExtension(f)).ToList();
}
All you need to do is ensure that your "weapons" files have a unique extension and call the method:
LoadFileNames(@"D:\Temp", ".txt", myListBox);
When the user selects a file, pull the file name from the list box, put the extension back on, and use Path.Combine to add the folder back in.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you for your response when i try to add in the list box name it wont add in the reverence i made and still at a little loss on how to execute this code to work right if that makes sense
image shows error.
http://i.imgur.com/hnung0v.png[^]
|
|
|
|
|
So what is "lstwep" when it's at home? It isn't a standard class - so I have no idea where you would find it!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
lstwep is what i named the listbox lst is short for listbox
|
|
|
|
|
So why did you change what I wrote and replace the class name with a variable name?
That is just like writing this:
string greetings = "Hello!";
private void MyMethod(greetings g)
{ Instead of:
string greetings = "Hello!";
private void MyMethod(string g)
{
...
}
...
MyMethod(greetings);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
bit i still get a issue when i add this in thats why i tried my best to remove this error
and i thout changing the name form listbox to elfwep witch is the name of my listbox but it still gives me the below error showed in the picture.
http://i.imgur.com/c6JH6TH.png[^]
|
|
|
|
|
That's because you don't have the using statement in your class...
using System.Windows.Forms;
You are supposed to know this stuff!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
lol yeah slipped my mind feel so stupid now ;( but how would i use that in the code i already have as in when i push a button it will load all the stuff into a listbox with the code you provided to me ? sorry im such a noob.
|
|
|
|
|
Interestingly, I couldn't find anything on this when I googled it. I have a ContextMenu with MenuItems and I want each MenuItem to have their own ContextMenu so I can both left and right click them. Trouble is, when I have code like this:
<MenuItem ContextMenu="{StaticResource MyContextMenu"/>
Right clicking on the MenuItem closes the MenuItem's parent ContextMenu instead of showing the MenuItem's ContextMenu. I've also experimented with adding StaysOpenOnClick="True" , but to no effect.
How can I do this? 
|
|
|
|
|
What is wrong to simply add sub items for the "main" menu items?
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I already do do that. The point is for the MenuItem to have children AND it's own ContextMenu. Google Chrome's bookmarks bar is a perfect example and clearly the logic is different than what you're suggesting.
I want this:
<MenuItem ContextMenu="{StaticResource MyContextMenu}">
<MenuItem/>
<MenuItem/>
<MenuItem/>
</MenuItem>
Obviously, I'm aware of submenus, but it's not quite the same.
|
|
|
|
|
I see and need to have a look to Chrome's bookmarks.
I made also some tests with WPF and was not able to make a ContextMenu for a "parent" ContextMenu item. I found that also RightClick the parent menu item ends in OnClick, which seems again to be an exceptional behaviour only for menu items.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Starting to suspect Chrome might only be using one menu for each bookmark and the bar itself. It looks like they enable/disable certain items depending on what's clicked. So if it's just one of those things you can't do, I'm cool with that. Just have to rethink what I want to do.
|
|
|
|
|
Strictly speaking, a ContextMenu is just an adorner - it should be possible for you to roll your own adorner abstraction to do what you want.
This space for rent
|
|
|
|
|
I'm with 0x01AA on this, use a sub menu, left click on a menu item is not intuitive and is probably not supported.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a class that has no parameters then i will create an object of it and convert it to stream and store it into a dictionary, every thing is fine until i add parameter to the class.
basically i do this.
var classObject = new ClassObject();
dictionary.Add(id, new MemoryStream());
then i will just retrieve it like this.
var retriveObject = dictionary[id] as ClassObject;
Now I add a single parameter on that class now using the last code above will produce Quote: no parameterless constructor defined for this object
my question, is there way to fix the exception without removing the parameter i added to the class?
Thanks
|
|
|
|
|
Gilbert Consellado wrote: is there way to fix the exception without removing the parameter i added to the class
Which implies that your code sample doesn't reflect the current code:
var classObject = new ClassObject(); Has been changed to something like
var classObject = new ClassObject(myParameterValue); And the class constructor changed to something like
public classObject(SomeClass parameterName)
{
... As a result, the class no longer contains a parameterless constructor as the error message indicates.
Create a new constructor:
public classObject()
{
... And it should get rid of the error.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sorry, I think i didn't deliver my post right.
The first example, that is the old code, and I already remove that.
Actually the current code is something like this:
var classObject = new ClassObject(parameterValue);
dictionary.Add(id, new MemoryStream());
Then I retrieve it like this.
var retriveObject = dictionary[id] as ClassObject;
Thanks
|
|
|
|
|
If I try to duplicate what you have:
Dictionary<int, MemoryStream> dictionary = new Dictionary<int, MemoryStream>();
var classObject = new ClassObject("hello");
int id = 666;
dictionary.Add(id, new MemoryStream());
var retriveObject = dictionary[id] as ClassObject;
}
public class ClassObject : MemoryStream
{
public ClassObject(string s) { }
} I don't get an error - I do get a null value, but that's what I expect.
So how is my code different from yours?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hmmm, honestly I didn't know how to reply to this. It bothers me for a while.
I apology, but are you serious with that code snippet or you just give me a sarcastic reply?
P.S.
I didn't post the the whole code on may sample to make the post short.
|
|
|
|
|
No - I'm serious - I've just combined your code snippets into something that will compile and run to try and run down why you get the error in code that shouldn't give it. Obviously, I can't see code you haven't given us so I have to assume a minimum that gets it to compile - but I don;t expect it to match yours. It's there so you can explain where yours differs and to let me create a "closer" version for testing here.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Got it.
But i just decide to remove the parameter and just expose the property setter of one of its member, because it also introduce other code problem.
btw, thanks
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm positive you just need to add a parameterless constructor, EVEN if you don't intend to use it. You could always mark it internal too. I have to assume you're using an xml serializer because in my experience, this has always happened when an object lacked a parameterless constructor. I also have to assume that when you added a constructor with parameters, you removed the parameterless one. Can't do that...as a sidenote, it would be helpful to have explained how exactly you serialize the object for others to better understand your issue.
So basically, it should look like this:
[Serializable]
public class ClassObject : MemoryStream
{
internal ClassObject() { }
public ClassObject(string s) { }
}
|
|
|
|
|
Thanks, yeah it seems to work this way. But marking it internal will give the same error. Actually I use XtraReport a third party component it has SaveLayout and FromStream member.
But i just decide to remove the constructor parameter and just pass the value through a property.
P.S.
Whooo my ISP giving me crap right now.
|
|
|
|