|
A ListBox contains a collection of object s available under the Items property which can be enumerated with foreach . The only problem is that they are objects, and what is dispayed textually comes from each object's ToString method.
If you have put plain strings in the list then you can do a foreach like:
foreach(object item in listBox.Items)
if((string) item == textbox.Text)
If they are other objects then you will need to cast to that type and check the resulting instance for the string in whatever way is correct for you (a property, ToString() etc).
|
|
|
|
|
You could try this:
if (listbox1.Items.Contains(textbox1.Text))
{
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Or you could try not posting this everywhere you can think of...C#, Q&A, etc. It wastes time, and annoys some people.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi ,
I'm new file extension using serialization and deserialization ...
How i can set icon to my new file extension.
|
|
|
|
|
Honeyboy_20 wrote: How i can set icon to my new file extension
You'd need to register your file extension[^].
Bastard Programmer from Hell
|
|
|
|
|
|
Honeyboy_20 wrote: I want to set it programatically
The link explains how, I don't offer copy and paste code
Honeyboy_20 wrote: I'm found the method but the icon not appears
Read the "caveats" in the link that you posted.
Bastard Programmer from Hell
|
|
|
|
|
In the windows explorer, access tools->folder options...
From the displayed dialog using the third tab (File Types) You can set the Icon for the file type.
If you do it from the application itself, you should assign a Icon using the Resource editor of your IDE.
See U
http://www.mstecharticles.com/
|
|
|
|
|
hi
when i press '#' on text box i need to see '.' - how to do it ?
i work on C# - windows-mobile
thanks in advance
|
|
|
|
|
The code below makes many assumptions and there is more to do (like resetting the caret to the end of the textbox text), but this is essentially the answer to your question.
private void textbox1_TextChanged(object sender, EventArgs e)
{
TextBox textbox = sender as TextBox;
if (textbox.Text.EndsWith("#"))
{
textbox.Text = textbox.Text.Replace("#", ".");
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I respectfully disagree that this is the answer .
1) what if the user inserts a # in the middle of the string?
2) a bit of un-needed overhead like the EndsWidth and full on text replace, you are going to do that every time the text changes
3) loss of caret position as well
4) as you said, there is "more to do" with this solution
I think the other responder had a better solution where he simply patches the character on key down. No loss of caret position, etc.
I think both of you also missed the case where a selection replace occurs .
|
|
|
|
|
|
Why did people 1 vote this? If you excuse the hard coded ascii values, this solution actually works as OP wanted unlike the other response in this thread .
|
|
|
|
|
I see that this solution is missing the same edge cases that are always missed. What happens if text is pasted in using the context menu, or is dropped as the result of drag/drop.
|
|
|
|
|
Can use character conversion?
Get the "#" as 35
|
|
|
|
|
I was trying to delete a post here… The, "Delete Link", it is all grayed out.
So I am editing…
I'm just here to say hello.
-- modified 18-Dec-11 4:09am.
|
|
|
|
|
It's considered very bad form touting for reviews in this way. Your article will get the publicity it deserves without the need for forum messages.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Is my newbie-Ness showing?
|
|
|
|
|
Please don't delete your original message, as it prevents others from understanding what my response is referring to. Just take it on the chin and move on.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
okay, thanks again
|
|
|
|
|
Once a forum message has at least one reply, it can no longer be deleted. Your only recourse is to edit the contents.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Robert Widmark wrote: I'm just here to say hello.
Well, you plainly weren't just here to say hello. It's extremely irritating to see content moved out of context.
|
|
|
|
|
I am current trying to figure out how to read a mini dump file with code, I have an option to read the output of kd.exe and output in a form but i would rather try and figure out how to use the function MiniDumpReadDumpStream() contained within dbghelp.dll. I have search google to try and find something about it and c# but all i get is c++ examples and i honestly have no idea how to read c++. What is the best way to go about finding the info i need?
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern bool MiniDumpReadDumpStream(IntPtr BaseOfDump,
int StreamNumber,
ref MINIDUMP_DIRECTORY Dir,
ref IntPtr StreamPointer,
ref UInt32 StreamSize);
|
|
|
|
|
Gwarmo wrote: What is the best way to go about finding the info i need?
Find a working C++ version and translate it to C#, as there are no C# versions readily available.
Bastard Programmer from Hell
|
|
|
|