473,511 Members | 15,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong selected Item with surselection

2 New Member
*curselection

So I am very new to Ruby and Tk and I have a Problem, which solution I didn't find after hours of research:

I have a directory which contains many projects.
With the following code I insert the names of the existing projects into a Listbox:

Expand|Select|Wrap|Line Numbers
  1. $projects = Dir.entries("#{Dir.pwd}/projects")[2..-1] 
  2. $projects.each {|f| $list.insert 'end', f} 
  3.  
I created a searchbar with a button which allows to find a specific entry:

Expand|Select|Wrap|Line Numbers
  1. def searchprojects
  2.     searchedprojects = []
  3.     $list.clear()
  4.     if $spec_ent.to_s.empty?
  5.        $projects.each {|f| $list.insert 'end', f}
  6.     else 
  7.        $projects.each {|i|
  8.            i = i.to_s
  9.  
searchedprojects.insert(searchedprojects.length(), i) if i.downcase.include? $spec_ent.to_s.downcase}
searchedprojects.each {|f| $list.insert 'end', f}
end
end



And with the following code I chose the selected project (which shall be filtered before):

Expand|Select|Wrap|Line Numbers
  1. def show_project
  2.   # updates the status of the chosen project 
  3.   idx           = $list.curselection[0]
  4.   $proj_name    = $projects[idx]
  5.   $status.value = "Project chosen: #{$proj_name}"
  6. end
  7.  
My Problem: After I filtered the Listbox with my searchbar, and I chose a project in the Listbox, I get the wrong drectory(name), because of the index. For instance, when i filter the Listbox, it contains only 3 entries, and I chose the third, it will give me the third entry of the unfiltered Listbox.

Thanks for helping.
Nov 10 '15 #1
1 5280
madita1212
2 New Member
Solution:

Expand|Select|Wrap|Line Numbers
  1. def show_project
  2.   # updates the status of the chosen project 
  3.   chosenList    = $list.curselection()
  4.   chosenItem    = chosenList[0]
  5.   $proj_name    = $list.get(chosenItem)
  6.   $status.value = "Project chosen: #{$proj_name}"
  7. end
  8.  
Nov 10 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
22594
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
6
6125
by: David De Cotis | last post by:
Hello all, I am trying to go through a ListBox and verify if am item was selected. If an item was selected, I would like to get a handle of the item and simply do a response.write on the selected...
1
4917
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
3
2981
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
1
25707
by: acord | last post by:
Hi, I am having problem to get a value of the selected item from a dropdown listbox. Here is the JS function; function getSelectedItem(objSelect) { alert("in getSelectedItem"); alert...
6
22083
by: George | last post by:
Hi all, How can I get the value stored from the selected item and subitems of a listview? Thanks in advance, George
4
3212
by: Louly | last post by:
Hi everybody, I got the code for dimming a menu item from this group after looking for it for a long time thanks to those who share their experiences with the others :) The problem I'm facing...
0
1839
by: dev121 | last post by:
Hi, I am currently trying to copy a single selected item from a listbox control in vba (excel). So far I have got this code, which doesn't work. <code> Private Sub btnAddNewOrder_Click()
0
5934
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to yellow. Trouble is, the selected item does not...
2
3668
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.