Results 1 to 5 of 5

Thread: listbox/textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    listbox/textbox

    Hello

    I've got a textbox and everytime i type then press enter I want what I've just typed to also be placed into a listview on a tab.

    Example: if I type in "OP28" then press enter it puts two spaces after that word ready for another one if need be, but I also want it to put that word I just typed into a listview row. I could have numerous words in this text is like "OP28 OP29 OP30" etc and I want it to add individual words into an individual row in a listview.

    I thought about a listbox, but it doesn't go with how i want the design to be like and also i want to be able to type in the box without having to have another textbox just to add an item.

    Any help would be great, thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: listbox/textbox

    I'm presuming this is a single line text box so surely the logical thing to do would be to clear the textbox on Enter rather than extending the line? Apart from anything else it will save a lot of code tracking the position of the caret and what has just been typed!

    Anyway, you need to detect the Enter key using the textbox's KeyDown event. I'm assuming that you know how to add an item to a listview so it's plain sailing once you've done that.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: listbox/textbox

    oh yes I definitely agree it would be logical, however again the design doesn't really allow it, im not exactly helping myself with this system really aha

    Thanks for the reply anyway. I know how to add a row to the listview, how would I track the enter button?

    Cheers

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: listbox/textbox

    vb.net Code:
    1. Private Sub TextBox1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    2.         If e.KeyCode = Keys.Enter Then
    3.             TextBox1.AppendText("  ")
    4.             'do other stuff
    5.             e.SuppressKeyPress = True 'cancels the beep
    6.         End If
    7.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: listbox/textbox

    That's great thanks! I'll test it in the morning, but that will then be able totrack the enter button so it would place what I've just typed into a listview row (when I add the dim etc code) instead of the whole textbox? Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width