Jump to content

C# ListBox Data Question?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
nighthawk

nighthawk

    Newbie

  • Members
  • Pip
  • 5 posts
I want to have a listbox when the user selects an item, the item text shows in a textbox. But the problem is I want the item name to be shown in the listbox and when the item name is clicked I want the content to show up, not the name. For example, the user enters some HTML code for a webpage, then a title for the page. When the user clicks on the title of the page in the ListBox, the code shows up, not the title. Thanks for your help.

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Personally, the way I would implement this would be with some kind of a hash map, using the list box text as the key and the text box contents as the value. When the user clicks a list box entry, pull the value out of the hash map using the selected item text as the key. (If your list box entries are going to remain static with pre-defined entries, you could also do this much easier by storing the text box values in a string array, with their indices corresponding with the matching list box item's index. That way, when the user selected an item, all you have to do is pull the string in the array at the same index as the currently selected list box item.)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users