Creating a new file type - and creating Search function

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 38
Reputation: Ajantis is an unknown quantity at this point 
Solved Threads: 0
Ajantis Ajantis is offline Offline
Light Poster

Creating a new file type - and creating Search function

 
0
  #1
Dec 18th, 2008
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:

  1. String cb = comboBox.Text.ToString();
  2.  
  3.  
  4. if (textBox.Text.Contains(cb))
  5. {
  6. textBox.SelectionStart = textBox.Text.IndexOf(cb);
  7. textBox.SelectionLength = textBox.Text.Length;
  8. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Creating a new file type - and creating Search function

 
0
  #2
Dec 18th, 2008
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?
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: Ajantis is an unknown quantity at this point 
Solved Threads: 0
Ajantis Ajantis is offline Offline
Light Poster

Re: Creating a new file type - and creating Search function

 
0
  #3
Dec 19th, 2008
Originally Posted by LizR View Post
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. :/
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Creating a new file type - and creating Search function

 
0
  #4
Dec 19th, 2008
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"
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: Ajantis is an unknown quantity at this point 
Solved Threads: 0
Ajantis Ajantis is offline Offline
Light Poster

Re: Creating a new file type - and creating Search function

 
0
  #5
Dec 20th, 2008
Originally Posted by LizR View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Creating a new file type - and creating Search function

 
0
  #6
Dec 20th, 2008
Sounds reasonable to me, and finding the length of your search string is the easiest bit.
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,912
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Creating a new file type - and creating Search function

 
0
  #7
Dec 20th, 2008
textBox.SelectionLength = textBox.Text.Length
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: Ajantis is an unknown quantity at this point 
Solved Threads: 0
Ajantis Ajantis is offline Offline
Light Poster

Re: Creating a new file type - and creating Search function

 
1
  #8
Dec 20th, 2008
Originally Posted by ddanbe View Post
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?

  1. if (textBox.Text.Contains(comboBox.Text))
  2. {
  3.  
  4. textBox.Select(textBox.Text.IndexOf(comboBox.Text),comboBox.Text.Length);
  5.  
  6. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,912
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Creating a new file type - and creating Search function

 
1
  #9
Dec 20th, 2008
Weird. Maybe a textbox.Focus() might help (I have not tested it)
You said it well :
Still - everything is learning
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: Ajantis is an unknown quantity at this point 
Solved Threads: 0
Ajantis Ajantis is offline Offline
Light Poster

Re: Creating a new file type - and creating Search function

 
0
  #10
Dec 20th, 2008
Originally Posted by ddanbe View Post
Weird. Maybe a textbox.Focus() might help (I have not tested it)
You said it well :
Thanks friend.
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC