0

I have difficulties finding out if there is a way to create a link in a TextBox, that triggers another function in a program I made, basically what I have right now is this:

We have a database containing orders, and sometimes we need to search using wildcards, so we can search for ie orders from companies that contains foo. That part is OK, I have a function that then gives me the last 50 orders where CompanyName contains foo, output them in a TextBox including ordernumber, CompanyName and some other information.

So the output is 50 lines in my TextBox, each line with the information I need. Right now, we double click the ordernumber, and copy/paste that into another TextBox, and have a Button that calls the database with another call, that gives all information about the specific order.

Obviously, it would be much smarter if we could just click on the ordernumber, and get the same info without the hassle of copy/paste! I've searched deep and far, but all I can find is about links that opens a browser, but nothing that triggers an event / function.

Does anyone now of a method to acquire what I'm looking for?

  • 1
    Do you need to edit the text in the textbox? TextBox doesn't seem the appropriate control to display this information. Why don't you choose a DataGridView or even a ListBox? – Steve Jul 13 '16 at 21:43
  • 1
    While it's better to use a suitable control as offered in the comments or answers, but if you want to do it using a `TextBox` take a look at this post: [How to get specific text value from a textbox based upon the mouse position](http://stackoverflow.com/questions/13070841/how-to-get-specific-text-value-from-a-textbox-based-upon-the-mouse-position) – Reza Aghaei Jul 13 '16 at 21:45

2 Answers2

2

It sounds like a TextBox isn't the best control for this. Something like a ListBox would be better as it has events such as Click, DoubleClick, and SelectedValueChanged which can be used to perform the next method call.

If, for some reason, you have to use a TextBox then I would suggest using a RichTextBox instead as it provides much more functionality that would be suited to this.

keyboardP
  • 68,824
  • 13
  • 156
  • 205
0

I created a similar effect by creating a view of the results and used a button to display the order number. That way the button is replicated for the number of results, but still has the functionality to create new events, and has the hover function to let the user know its active.

tCoe
  • 401
  • 1
  • 5
  • 24
  • Thanks for pointing the obvious out, since this is "just" for internal use, I don't mind 50 buttons on the same page :) – Tommy Larsen Jul 14 '16 at 19:45