| | |
Creating a new file type - and creating Search function
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 38
Reputation:
Solved Threads: 0
Hello there!
I have questions about two things:
1.) How do I create a completely new type of files that can only be opened by my programe? What knowledge do I have to have to create something like this?
2.) I am trying to create a search function in a program for training purposes - viewing from MSDN's page. However, I can't make it work, and I've been trying for two days. When a button is clicked, the text in a textBox will searched depending on the text in my comboBox. When a text is found, it should me selected programmatically.
This is how I did:
I have questions about two things:
1.) How do I create a completely new type of files that can only be opened by my programe? What knowledge do I have to have to create something like this?
2.) I am trying to create a search function in a program for training purposes - viewing from MSDN's page. However, I can't make it work, and I've been trying for two days. When a button is clicked, the text in a textBox will searched depending on the text in my comboBox. When a text is found, it should me selected programmatically.
This is how I did:
C# Syntax (Toggle Plain Text)
String cb = comboBox.Text.ToString(); if (textBox.Text.Contains(cb)) { textBox.SelectionStart = textBox.Text.IndexOf(cb); textBox.SelectionLength = textBox.Text.Length; }
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
1. You can register a file extension in the registry, and as long as your program knows how to open it from a command line and you put that in the registry too. It will work (for examples see the plethera already in your registry)
2. At first glace that code looks like it should select from the beginning of the stuff found to the end of the text, so, what isnt it doing?
2. At first glace that code looks like it should select from the beginning of the stuff found to the end of the text, so, what isnt it doing?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Aug 2008
Posts: 38
Reputation:
Solved Threads: 0
•
•
•
•
1. You can register a file extension in the registry, and as long as your program knows how to open it from a command line and you put that in the registry too. It will work (for examples see the plethera already in your registry)
2. At first glace that code looks like it should select from the beginning of the stuff found to the end of the text, so, what isnt it doing?
Allright, I am not so knowledgeable about registries and how to edit them. Do you know any document I could read about doing this so I can try creating a new file type?

That code I post is supposed to search all occurences of a text in a textBox, that is written in the comboBox, and select it. But it does neither. :/
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
OK for your file association: http://letmegooglethatforyou.com/?q=...le+association
As for the code, well the .ToString() is kinda pointless as well .Text returns as string anyway, so, perhaps this means your cb doesnt contain what you thought .. did you look?
Also, the code you show as I said earlier looks like it would find a first occurance of something and highlight to the end? is that what you see? Also remember it would want to be exactly the same so "test" doesnt equal "Test"
As for the code, well the .ToString() is kinda pointless as well .Text returns as string anyway, so, perhaps this means your cb doesnt contain what you thought .. did you look?
Also, the code you show as I said earlier looks like it would find a first occurance of something and highlight to the end? is that what you see? Also remember it would want to be exactly the same so "test" doesnt equal "Test"
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Aug 2008
Posts: 38
Reputation:
Solved Threads: 0
•
•
•
•
OK for your file association: http://letmegooglethatforyou.com/?q=...le+association
As for the code, well the .ToString() is kinda pointless as well .Text returns as string anyway, so, perhaps this means your cb doesnt contain what you thought .. did you look?
Also, the code you show as I said earlier looks like it would find a first occurance of something and highlight to the end? is that what you see? Also remember it would want to be exactly the same so "test" doesnt equal "Test"
Thanks for the link!
I will be checking it in a moment.Oh ok! Now I see. Yes it was pretty pointless having .toString().
I added comboBox.Text instead.
Well, I was learning this from MSDN, so I tried to do like them. According from what I read, and as far as I understood it, the SelectionStart at indexOf() should start selecting the word I am seeking where it is first found in the textBox. Later, the selection starts from that index, and selects depending on the length of the word.
But - I couldn't make it work. Besides, now that I take a closer look at the code - the SelectionLength would select the whole Text box... due to the:
textBox.SelectionLength = textBox.Text.Length;
If I am not misstaken. But still - I am no closer to the solution. :/
I can't get the selection to start properly...
and I need to know how long the word that I search for is, so that that amount can be selected. I think... what do you say?
•
•
•
•
textBox.SelectionLength = textBox.Text.Length
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Aug 2008
Posts: 38
Reputation:
Solved Threads: 0
•
•
•
•
You are using the total length of the text in the textbox here, try using cb.Length. You can also use the Select method instead : Select(start,length) which is equivalent in what you are trying to do.
Riiiiiight! Ahh man - that I missed it!
Thanks a lot! I can't believe I didn't see that! Haha. Still - everything is learning.
Each situation.But I still have one problem - it won't select. Nothing shows up.
Am I missing something out?
C# Syntax (Toggle Plain Text)
if (textBox.Text.Contains(comboBox.Text)) { textBox.Select(textBox.Text.IndexOf(comboBox.Text),comboBox.Text.Length); }
•
•
Join Date: Aug 2008
Posts: 38
Reputation:
Solved Threads: 0
•
•
•
•
Weird. Maybe a textbox.Focus() might help (I have not tested it)
You said it well :
Hey! What do you know!?
It actually works! Woohoo! Niiiice!I wonder what that .Focus() thing does... I'll google it up later on.
Now to the next step... I want the Search function to find all the occurences of the comboBox's text in the textBox, and select them.
The way it looks like now only selects the first occurence....
But perhaps if I use a loop...
I'll go try it out now.
EDIT: Tried it out again. But no change has been made. I should have figured. If I add a loop - the only thing that WILL be repeated is the actual function - so no other text will be selected.
I wonder how I search through the whole text box and select all the occurences of the text written in the combobox... Last edited by Ajantis; Dec 20th, 2008 at 8:20 pm. Reason: Tried out the solution
![]() |
Similar Threads
- How do I restore to Original Factory Settings with Vista? (Windows Vista and Windows 7)
- creating order/order detail insert forms (ASP)
- DLLs and LIBs - what, why, and how? (C++)
- Help me with my myspace clone (PHP)
- Creating a VB dll (Visual Basic 4 / 5 / 6)
- Problems using a php generator (PHP)
Other Threads in the C# Forum
- Previous Thread: another question about ComboBox
- Next Thread: textbox value check with Access
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development draganddrop drawing encryption enum event excel file filename finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile gis globalization gtk httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml






